From 9e45032bd53d07e78c2ec41f1ae9d0d75e4910ce Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 1 Apr 2012 23:10:46 +0200 Subject: Add timestamps to log messages --- src/fastd.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/fastd.h') 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) -- cgit v1.2.3