#include <stdlib.h>
#include <string.h>
#include <time.h>
+#include <sys/time.h>
#include <glib.h>
#include "file.h"
#include "item.h"
#include <windowsx.h>
#endif
-int debug_level=0,segv_level=0;
+int debug_level=0;
+int segv_level=0;
+int timestamp_prefix=0;
+
static int dummy;
static GHashTable *debug_hash;
static const char *gdb_program;
void
debug_level_set(const char *name, int level)
{
- debug_level=0;
- if (strcmp(name,"segv")) {
- g_hash_table_insert(debug_hash, g_strdup(name), (gpointer) level);
- g_hash_table_foreach(debug_hash, debug_update_level, NULL);
- } else {
+ if (!strcmp(name, "segv")) {
segv_level=level;
if (segv_level)
signal(SIGSEGV, sigsegv);
else
signal(SIGSEGV, NULL);
+ } else if (!strcmp(name, "timestamps")) {
+ timestamp_prefix=level;
+ } else {
+ debug_level=0;
+ g_hash_table_insert(debug_hash, g_strdup(name), (gpointer) level);
+ g_hash_table_foreach(debug_hash, debug_update_level, NULL);
}
}
return (int)(g_hash_table_lookup(debug_hash, name));
}
+static void debug_timestamp(FILE *fp)
+{
+ struct timeval tv;
+
+ if (gettimeofday(&tv, NULL) == -1)
+ return;
+ /* Timestamps are UTC */
+ fprintf(fp,
+ "%02d:%02d:%02d.%03d|",
+ (int)(tv.tv_sec/3600)%24,
+ (int)(tv.tv_sec/60)%60,
+ (int)tv.tv_sec % 60,
+ (int)tv.tv_usec/1000);
+}
+
void
debug_vprintf(int level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt, va_list ap)
{
#ifndef DEBUG_WIN32_CE_MESSAGEBOX
if (! fp)
fp = stderr;
+ if (timestamp_prefix)
+ debug_timestamp(fp);
if (prefix)
fprintf(fp,"%s:",buffer);
vfprintf(fp,fmt, ap);
<plugin path="$NAVIT_LIBDIR/*/${NAVIT_LIBPREFIX}libgraphics_null.so" active="no" />
</plugins>
<debug name="navit:do_draw" level="0" />
- <debug name="segv" level="1" />
+ <!-- segv: 1 - show backtrace with gdb and exit, 2 - stay in gdb -->
+ <debug name="segv" level="1" />
+ <!-- timestamps 0/1 - prefix log messages with a timestamp -->
+ <debug name="timestamps" level="0" />
<!--
Center coordinates format: