]> git.itanic.dy.fi Git - rrdd/commitdiff
debug.h: Add timestamps to debug prints
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Thu, 12 Apr 2012 18:47:24 +0000 (21:47 +0300)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Thu, 12 Apr 2012 19:05:45 +0000 (22:05 +0300)
This is useful when someone needs to run rrdd for long time and debug
the behavior from logs. Especially timing issues become easier to
understand once the timestamps are visible.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
debug.h

diff --git a/debug.h b/debug.h
index 34e448f83727205d41d45a960d2c94f789079347..1411313f64c1ed0c412a45af1f3e59b797d06bba 100644 (file)
--- a/debug.h
+++ b/debug.h
@@ -1,6 +1,7 @@
 #ifndef __DEBUG_H
 #define __DEBUG_H
 
+#include <time.h>
 #include <unistd.h>
 #include "process.h"
 
@@ -10,10 +11,16 @@ extern const char normal_color[];
 
 #define pr_info(fmt, arg...)                                           \
        do {                                                            \
+               time_t t = time(0);                                     \
                char indent[16] = { "               " };                \
+               char time[32];                                          \
+                                                                       \
+               strftime(time, sizeof(time), "%d.%m.%Y %T ",            \
+                       localtime(&t));                                 \
                indent[get_parent_count()] = 0;                         \
-               fprintf(stderr, "%s%s[%5d.%d] %s:%d %s"                 \
-                       fmt, indent, green_color,                       \
+                                                                       \
+               fprintf(stderr, "%s%s %s[%5d.%d] %s:%d %s"              \
+                       fmt, green_color, time, indent,                 \
                        getpid(), get_sibling_count(),                  \
                        __FILE__, __LINE__, normal_color, ##arg);       \
        } while (0)
@@ -21,10 +28,16 @@ extern const char normal_color[];
 
 #define pr_err(fmt, arg...)                                            \
        do {                                                            \
+               time_t t = time(0);                                     \
                char indent[16] = { "               " };                \
+               char time[32];                                          \
+                                                                       \
+               strftime(time, sizeof(time), "%d.%m.%Y %T ",            \
+                       localtime(&t));                                 \
                indent[get_parent_count()] = 0;                         \
-               fprintf(stderr, "%s%s[%5d.%d] %s:%d Error %s"           \
-                       fmt, indent, red_color,                         \
+                                                                       \
+               fprintf(stderr, "%s%s %s[%5d.%d] %s:%d Error %s"        \
+                       fmt, red_color, time, indent,                   \
                        getpid(), get_sibling_count(),                  \
                        __FILE__, __LINE__, normal_color, ##arg);       \
        } while (0)