Add:core:Interface to redirect the console log to a file
authorzaxl <zaxl@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 28 Oct 2008 22:54:01 +0000 (22:54 +0000)
committerzaxl <zaxl@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 28 Oct 2008 22:54:01 +0000 (22:54 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@1601 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/debug.c
navit/debug.h
navit/start.c

index d83d546..6bb5b2d 100644 (file)
@@ -34,6 +34,8 @@ static int dummy;
 static GHashTable *debug_hash;
 static char *gdb_program;
 
+static FILE *debug_fp;
+
 static void sigsegv(int sig)
 {
 #if defined(_WIN32) || defined(__CEGCC__)
@@ -54,6 +56,7 @@ debug_init(const char *program_name)
        gdb_program=program_name;
        signal(SIGSEGV, sigsegv);
        debug_hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+       debug_fp = stderr;
 }
 
 
@@ -107,8 +110,9 @@ debug_vprintf(int level, const char *module, const int mlen, const char *functio
        sprintf(buffer, "%s:%s", module, function);
        if (debug_level_get(module) >= level || debug_level_get(buffer) >= level) {
                if (prefix)
-                       fprintf(stderr,"%s:",buffer);
-               vfprintf(stderr,fmt, ap);
+                       fprintf(debug_fp,"%s:",buffer);
+               vfprintf(debug_fp,fmt, ap);
+               fflush(debug_fp);
        }
 }
 
@@ -127,3 +131,26 @@ debug_assert_fail(char *module, const int mlen,const char *function, const int f
        debug_printf(0,module,mlen,function,flen,1,"%s:%d assertion failed:%s\n", file, line, expr);
        abort();
 }
+
+void
+debug_destroy(void)
+{
+       if (!debug_fp)
+               return;
+       if (debug_fp == stderr || debug_fp == stdout)
+               return;
+       fclose(debug_fp);
+       debug_fp = NULL;
+}
+
+void debug_set_logfile(const char *path)
+{
+       FILE *fp;
+       fp = fopen(path, "a");
+       if (fp) {
+               debug_destroy();
+               debug_fp = fp;
+               fprintf(debug_fp, "Navit log started\n");
+               fflush(debug_fp);
+       }
+}
index 5a0317e..f9b520f 100644 (file)
@@ -35,6 +35,8 @@ extern int debug_level;
 /* prototypes */
 struct attr;
 void debug_init(const char *program_name);
+void debug_destroy(void);
+void debug_set_logfile(const char *path);
 void debug_level_set(const char *name, int level);
 int debug_level_get(const char *name);
 struct debug *debug_new(struct attr *parent, struct attr **attrs);
index 80eba43..621f708 100644 (file)
@@ -84,6 +84,9 @@ int main(int argc, char **argv)
        main_init(argv[0]);
        main_init_nls();
        debug_init(argv[0]);
+#ifdef __CEGCC__
+       debug_set_logfile("/Storage Card/navit.log");
+#endif
        file_init();
 #ifndef USE_PLUGINS
        extern void builtin_init(void);