Changed level setter
This commit is contained in:
parent
0b1f14ad83
commit
755958ce14
|
@ -5,6 +5,20 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <glib.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 gint debug_level = DEBUG_ALWAYS;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -21,7 +35,7 @@ gm_debug_msg(gint level, gchar *line, ...) {
|
||||||
time_t timer;
|
time_t timer;
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
if (debug_level | level == debug_level) {
|
if ((debug_level | level) == debug_level) {
|
||||||
va_start(args, line);
|
va_start(args, line);
|
||||||
timer = time(0);
|
timer = time(0);
|
||||||
timet = localtime(&timer);
|
timet = localtime(&timer);
|
||||||
|
@ -30,7 +44,7 @@ gm_debug_msg(gint level, gchar *line, ...) {
|
||||||
gm_debug_msg_real(stdout, timet, line, args);
|
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);
|
gm_debug_msg_real(stderr, timet, line, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +53,25 @@ gm_debug_msg(gint level, gchar *line, ...) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
debug_set_level(gint level) {
|
gm_debug_set_level(gchar *level) {
|
||||||
debug_level = 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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,11 @@
|
||||||
typedef enum _GmDebugLevel {
|
typedef enum _GmDebugLevel {
|
||||||
DEBUG_ALWAYS = 1 << 1,
|
DEBUG_ALWAYS = 1 << 1,
|
||||||
DEBUG_DEFAULT = 1 << 2,
|
DEBUG_DEFAULT = 1 << 2,
|
||||||
DEBUG_MCP = 1 << 3
|
DEBUG_MCP = 1 << 3,
|
||||||
|
DEBUG_ALL = 0xFFFF
|
||||||
} GmDebugLevel;
|
} GmDebugLevel;
|
||||||
|
|
||||||
void gm_debug_msg(GmDebugLevel level, char *line, ...);
|
void gm_debug_msg(gint level, char *line, ...);
|
||||||
void gm_debug_set_level(GmDebugLevel level);
|
void gm_debug_set_level(gchar *level);
|
||||||
|
|
||||||
#endif /* __GM_DEBUG_H__ */
|
#endif /* __GM_DEBUG_H__ */
|
||||||
|
|
Reference in a new issue