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 | |
parent | e0a3556742a81e6cb6e72590b2696ea39e9872ea (diff) | |
download | fastd-9e45032bd53d07e78c2ec41f1ae9d0d75e4910ce.tar fastd-9e45032bd53d07e78c2ec41f1ae9d0d75e4910ce.zip |
Add timestamps to log messages
-rw-r--r-- | src/fastd.h | 14 | ||||
-rw-r--r-- | src/printf.c | 8 |
2 files changed, 17 insertions, 5 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) diff --git a/src/printf.c b/src/printf.c index 53298bf..7c922c5 100644 --- a/src/printf.c +++ b/src/printf.c @@ -195,10 +195,10 @@ void fastd_printf(const fastd_context *ctx, const char *format, ...) { if (p) { if (inet_ntop(flag_l ? AF_INET6 : AF_INET, p, addr_buf, sizeof(addr_buf))) - fprintf(stderr, "%s", addr_buf); + fputs(addr_buf, stderr); } else { - fprintf(stderr, "(null)"); + fputs("(null)", stderr); } break; @@ -211,7 +211,7 @@ void fastd_printf(const fastd_context *ctx, const char *format, ...) { eth_addr->data[3], eth_addr->data[4], eth_addr->data[5]); } else { - fprintf(stderr, "(null)"); + fputs("(null)", stderr); } break; @@ -221,7 +221,7 @@ void fastd_printf(const fastd_context *ctx, const char *format, ...) { if (peer) print_peer_str(ctx, peer); else - fprintf(stderr, "(null)"); + fputs("(null)", stderr); break; default: |