Improved debugging facilities
This commit is contained in:
parent
bd9e4d10d6
commit
13e89cb1f2
59
src/debug.c
59
src/debug.c
|
@ -5,35 +5,40 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
int dbgLevel = 0;
|
static gint debug_level = DEBUG_ALWAYS;
|
||||||
|
|
||||||
void
|
static void
|
||||||
debug_msg(int level, char *line, ...) {
|
gm_debug_msg_real(FILE *f, struct tm *timet, gchar *line, va_list args) {
|
||||||
struct tm *timet;
|
fprintf(f, "[%02d:%02d:%02d] # ", timet->tm_hour, timet->tm_min,
|
||||||
time_t timer;
|
timet->tm_sec);
|
||||||
va_list args;
|
vfprintf(f, line, args);
|
||||||
FILE *f;
|
fprintf(f, "\n");
|
||||||
|
|
||||||
if (dbgLevel >= level) {
|
|
||||||
va_start(args, line);
|
|
||||||
timer = time(0);
|
|
||||||
timet = localtime(&timer);
|
|
||||||
|
|
||||||
if (level == 0) {
|
|
||||||
f = stdout;
|
|
||||||
} else {
|
|
||||||
f = stderr;
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(f, "[%02d:%02d:%02d] # ", timet->tm_hour, timet->tm_min,
|
|
||||||
timet->tm_sec);
|
|
||||||
vfprintf(f, line, args);
|
|
||||||
printf("\n");
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
debug_set_level(int level) {
|
gm_debug_msg(gint level, gchar *line, ...) {
|
||||||
dbgLevel = level;
|
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;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue