From 13e89cb1f290ec340f59f4e2542968addb62a220 Mon Sep 17 00:00:00 2001 From: Jesse van den Kieboom Date: Sun, 6 Nov 2005 16:20:30 +0000 Subject: [PATCH] Improved debugging facilities --- src/debug.c | 53 +++++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/debug.c b/src/debug.c index 577d45b..c820441 100644 --- a/src/debug.c +++ b/src/debug.c @@ -5,35 +5,40 @@ #include #include -int dbgLevel = 0; +static gint debug_level = DEBUG_ALWAYS; + +static void +gm_debug_msg_real(FILE *f, struct tm *timet, gchar *line, va_list args) { + fprintf(f, "[%02d:%02d:%02d] # ", timet->tm_hour, timet->tm_min, + timet->tm_sec); + vfprintf(f, line, args); + fprintf(f, "\n"); +} void -debug_msg(int level, char *line, ...) { - struct tm *timet; - time_t timer; - va_list args; - FILE *f; +gm_debug_msg(gint level, gchar *line, ...) { + struct tm *timet; + time_t timer; + va_list args; - if (dbgLevel >= level) { - va_start(args, line); - timer = time(0); - timet = localtime(&timer); - - if (level == 0) { - f = stdout; - } else { - f = stderr; - } + if (debug_level | level == debug_level) { + va_start(args, line); + timer = time(0); + timet = localtime(&timer); - fprintf(f, "[%02d:%02d:%02d] # ", timet->tm_hour, timet->tm_min, - timet->tm_sec); - vfprintf(f, line, args); - printf("\n"); - va_end(args); - } + if (level & DEBUG_ALWAYS) { + gm_debug_msg_real(stdout, timet, line, args); + } + + if (level & DEBUG_ALWAYS != level) { + gm_debug_msg_real(stderr, timet, line, args); + } + + va_end(args); + } } void -debug_set_level(int level) { - dbgLevel = level; +debug_set_level(gint level) { + debug_level = level; }