From 3c9fb56df5c39c09efc45752e8987a9b8fb4b877 Mon Sep 17 00:00:00 2001 From: Jesse van den Kieboom Date: Sun, 6 Nov 2005 16:20:55 +0000 Subject: [PATCH] Filename changed --- src/gm-debug.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/gm-debug.c diff --git a/src/gm-debug.c b/src/gm-debug.c new file mode 100644 index 0000000..c820441 --- /dev/null +++ b/src/gm-debug.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +#include + +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 +gm_debug_msg(gint level, gchar *line, ...) { + struct tm *timet; + time_t timer; + va_list args; + + if (debug_level | level == debug_level) { + va_start(args, line); + timer = time(0); + timet = localtime(&timer); + + 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(gint level) { + debug_level = level; +}