Changed level setter

This commit is contained in:
Jesse van den Kieboom 2005-11-07 09:46:20 +00:00
parent 0b1f14ad83
commit 755958ce14
2 changed files with 41 additions and 7 deletions

View File

@ -5,6 +5,20 @@
#include <errno.h>
#include <glib.h>
#include "gm-debug.h"
typedef struct _LevelMap {
gchar const *name;
GmDebugLevel level;
} LevelMap;
static LevelMap level_mapping[] = {
{"default", DEBUG_DEFAULT},
{"mcp", DEBUG_MCP},
{"all", DEBUG_ALL},
{NULL, 0}
};
static gint debug_level = DEBUG_ALWAYS;
static void
@ -21,7 +35,7 @@ gm_debug_msg(gint level, gchar *line, ...) {
time_t timer;
va_list args;
if (debug_level | level == debug_level) {
if ((debug_level | level) == debug_level) {
va_start(args, line);
timer = time(0);
timet = localtime(&timer);
@ -30,7 +44,7 @@ gm_debug_msg(gint level, gchar *line, ...) {
gm_debug_msg_real(stdout, timet, line, args);
}
if (level & DEBUG_ALWAYS != level) {
if ((level & DEBUG_ALWAYS) != level) {
gm_debug_msg_real(stderr, timet, line, args);
}
@ -39,6 +53,25 @@ gm_debug_msg(gint level, gchar *line, ...) {
}
void
debug_set_level(gint level) {
debug_level = level;
gm_debug_set_level(gchar *level) {
gchar **levels, **iter;
debug_level = DEBUG_ALWAYS;
LevelMap *map;
if (level == NULL) {
return;
}
levels = g_strsplit(level, ",", -1);
for (iter = levels; *iter; ++iter) {
for (map = level_mapping; map->name; ++map) {
if (strcasecmp(map->name, *iter) == 0) {
debug_level = debug_level | map->level;
break;
}
}
}
g_strfreev(levels);
}

View File

@ -4,10 +4,11 @@
typedef enum _GmDebugLevel {
DEBUG_ALWAYS = 1 << 1,
DEBUG_DEFAULT = 1 << 2,
DEBUG_MCP = 1 << 3
DEBUG_MCP = 1 << 3,
DEBUG_ALL = 0xFFFF
} GmDebugLevel;
void gm_debug_msg(GmDebugLevel level, char *line, ...);
void gm_debug_set_level(GmDebugLevel level);
void gm_debug_msg(gint level, char *line, ...);
void gm_debug_set_level(gchar *level);
#endif /* __GM_DEBUG_H__ */