Add:Core:New "global" debug level; activate option -d.
authorsleske <sleske@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sun, 29 Jan 2012 14:49:58 +0000 (14:49 +0000)
committersleske <sleske@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sun, 29 Jan 2012 14:49:58 +0000 (14:49 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@4915 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/debug.c
navit/navit/debug.h
navit/navit/start_real.c

index 0a2502d..4343ace 100644 (file)
@@ -52,7 +52,8 @@ static struct sockaddr_in debug_sin;
 #endif
 
 
-int debug_level=0;
+int max_debug_level=0;
+int global_debug_level=0;
 int segv_level=0;
 int timestamp_prefix=0;
 
@@ -99,8 +100,8 @@ debug_init(const char *program_name)
 static void
 debug_update_level(gpointer key, gpointer value, gpointer user_data)
 {
-       if (debug_level < GPOINTER_TO_INT(value))
-               debug_level = GPOINTER_TO_INT(value);
+       if (max_debug_level < GPOINTER_TO_INT(value))
+               max_debug_level = GPOINTER_TO_INT(value);
 }
 
 void
@@ -114,8 +115,12 @@ debug_level_set(const char *name, int level)
                        signal(SIGSEGV, NULL);
        } else if (!strcmp(name, "timestamps")) {
                timestamp_prefix=level;
+       } else if (!strcmp(name, DEBUG_MODULE_GLOBAL)) {
+               global_debug_level=level;
+               if (max_debug_level < global_debug_level){
+                       max_debug_level = global_debug_level;
+               }
        } else {
-               debug_level=0;
                g_hash_table_insert(debug_hash, g_strdup(name), GINT_TO_POINTER(level));
                g_hash_table_foreach(debug_hash, debug_update_level, NULL);
        }
@@ -204,7 +209,7 @@ debug_vprintf(int level, const char *module, const int mlen, const char *functio
        FILE *fp=debug_fp;
 
        sprintf(buffer, "%s:%s", module, function);
-       if (debug_level_get(module) >= level || debug_level_get(buffer) >= level) {
+       if (global_debug_level >= level || debug_level_get(module) >= level || debug_level_get(buffer) >= level) {
 #if defined(DEBUG_WIN32_CE_MESSAGEBOX)
                wchar_t muni[4096];
 #endif
index 31cdab3..f96ca4e 100644 (file)
@@ -31,13 +31,15 @@ extern "C" {
 #define __PRETTY_FUNCTION__ __FUNCTION__
 #endif
 
-extern int debug_level;
+extern int max_debug_level;
 #define dbg_str2(x) #x
 #define dbg_str1(x) dbg_str2(x)
 #define dbg_module dbg_str1(MODULE)
-#define dbg(level,...) { if (debug_level >= level) debug_printf(level,dbg_module,strlen(dbg_module),__PRETTY_FUNCTION__, strlen(__PRETTY_FUNCTION__),1,__VA_ARGS__); }
+#define dbg(level,...) { if (max_debug_level >= level) debug_printf(level,dbg_module,strlen(dbg_module),__PRETTY_FUNCTION__, strlen(__PRETTY_FUNCTION__),1,__VA_ARGS__); }
 #define dbg_assert(expr) ((expr) ? (void) 0 : debug_assert_fail(dbg_module,strlen(dbg_module),__PRETTY_FUNCTION__, strlen(__PRETTY_FUNCTION__),__FILE__,__LINE__,dbg_str1(expr)))
 
+#define DEBUG_MODULE_GLOBAL "global"
+
 #ifdef DEBUG_MALLOC
 #undef g_new
 #undef g_new0
index 5dc3d18..d07c68d 100644 (file)
@@ -57,7 +57,7 @@ char **main_argv;
 static void
 print_usage(void)
 {
-       printf(_("navit usage:\nnavit [options] [configfile]\n\t-c <file>: use <file> as config file\n\t-d <n>: set the debug output level to <n>. (TODO)\n\t-h: print this usage info and exit.\n\t-v: Print the version and exit.\n"));
+       printf(_("navit usage:\nnavit [options] [configfile]\n\t-c <file>: use <file> as config file\n\t-d <n>: set the global debug output level to <n> (0-3).\n\t-h: print this usage info and exit.\n\t-v: Print the version and exit.\n"));
 }
 
 
@@ -130,7 +130,7 @@ int main_real(int argc, char **argv)
                    config_file = optarg;
                                break;
                        case 'd':
-                               printf("TODO Verbose option is set to `%s'\n", optarg);
+                               debug_level_set(DEBUG_MODULE_GLOBAL, atoi(optarg));
                                break;
                        case 'e':
                                command=optarg;