From 21c9da762090af21365a70535b46374606e8355f Mon Sep 17 00:00:00 2001 From: zaxl Date: Tue, 28 Oct 2008 22:54:01 +0000 Subject: [PATCH] Add:core:Interface to redirect the console log to a file git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@1601 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/navit/debug.c | 31 +++++++++++++++++++++++++++++-- navit/navit/debug.h | 2 ++ navit/navit/start.c | 3 +++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/navit/navit/debug.c b/navit/navit/debug.c index d83d546..6bb5b2d 100644 --- a/navit/navit/debug.c +++ b/navit/navit/debug.c @@ -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); + } +} diff --git a/navit/navit/debug.h b/navit/navit/debug.h index 5a0317e..f9b520f 100644 --- a/navit/navit/debug.h +++ b/navit/navit/debug.h @@ -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); diff --git a/navit/navit/start.c b/navit/navit/start.c index 80eba43..621f708 100644 --- a/navit/navit/start.c +++ b/navit/navit/start.c @@ -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); -- 2.7.4