40 lines
657 B
C
40 lines
657 B
C
#include <time.h>
|
|
#include <stdio.h>
|
|
#include <stdarg.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include <glib.h>
|
|
|
|
int dbgLevel = 0;
|
|
|
|
void
|
|
debug_msg(int level, char *line, ...) {
|
|
struct tm *timet;
|
|
time_t timer;
|
|
va_list args;
|
|
FILE *f;
|
|
|
|
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
|
|
debug_set_level(int level) {
|
|
dbgLevel = level;
|
|
}
|