]> git.itanic.dy.fi Git - rrdd/commitdiff
debug: Reintroduce message colouring
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Tue, 26 Jun 2012 13:40:58 +0000 (16:40 +0300)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Tue, 26 Jun 2012 13:47:29 +0000 (16:47 +0300)
When the debug macros were refactored into a separate function, all
messages were printed with green color. Change it to use the desired
color instead.

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

diff --git a/debug.c b/debug.c
index 8f98649b013de599df618146a0b0ab46ef1cf588..3c635fba772d27da30bc6c55efcd7acfc810da09 100644 (file)
--- a/debug.c
+++ b/debug.c
@@ -19,6 +19,18 @@ const char normal_color[] = {
 
 int trace_level = 1;
 
+static const char *assign_color(int color)
+{
+       switch (color) {
+       case 1:
+               return red_color;
+       case 2:
+               return green_color;
+       default:
+               return normal_color;
+       }
+}
+
 void print_trace(const char *file, int line, int color, int l,
                const char *fmt, ...)
 {
@@ -26,6 +38,7 @@ void print_trace(const char *file, int line, int color, int l,
        time_t t = time(0);
        char time[32];
        char trace[1024];
+       const char *color_str = assign_color(color);
 
        if (l > trace_level)
                return;
@@ -37,7 +50,7 @@ void print_trace(const char *file, int line, int color, int l,
        strftime(time, sizeof(time), "%d.%m.%Y %T ", localtime(&t));
 
        fprintf(stderr, "%s%s [%5d.%d] %s:%d %s %s",
-               green_color, time,
+               color_str, time,
                getpid(), get_parent_count(),
                file, line, normal_color, trace);
        fflush(stderr);