diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-04-01 23:10:46 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-04-01 23:10:46 +0200 |
commit | 9e45032bd53d07e78c2ec41f1ae9d0d75e4910ce (patch) | |
tree | d5b373fc0781751327447f59ff90321a5f9b6f42 /src/fastd.h | |
parent | e0a3556742a81e6cb6e72590b2696ea39e9872ea (diff) | |
download | fastd-9e45032bd53d07e78c2ec41f1ae9d0d75e4910ce.tar fastd-9e45032bd53d07e78c2ec41f1ae9d0d75e4910ce.zip |
Add timestamps to log messages
Diffstat (limited to 'src/fastd.h')
-rw-r--r-- | src/fastd.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/fastd.h b/src/fastd.h index e48929d..8f53409 100644 --- a/src/fastd.h +++ b/src/fastd.h @@ -144,7 +144,19 @@ static inline int fastd_rand(fastd_context *ctx, int min, int max) { #define pr_log(ctx, level, prefix, args...) do { \ if ((ctx)->conf == NULL || (level) <= (ctx)->conf->loglevel) { \ - fputs(prefix, stderr); fastd_printf(ctx, args); fputs("\n", stderr); \ + char timestr[100]; \ + time_t t; \ + struct tm tm; \ + \ + t = time(NULL); \ + if (localtime_r(&t, &tm) != NULL) { \ + if (strftime(timestr, sizeof(timestr), "%F %T %z --- ", &tm) > 0) \ + fputs(timestr, stderr); \ + } \ + \ + fputs(prefix, stderr); \ + fastd_printf(ctx, args); \ + fputs("\n", stderr); \ } \ } while(0) |