Permalink
Browse files

improve debug infomation, add time/file/line info.

  • Loading branch information...
1 parent 22678bd commit af5b293534a5c6f6ecfb670da6d590574c55b561 @soarpenguin committed Feb 25, 2014
Showing with 14 additions and 2 deletions.
  1. +4 −1 include/debug.h
  2. +10 −1 src/debug.c
View
5 include/debug.h
@@ -31,7 +31,10 @@ typedef enum
} log_level_t;
-void do_debug(log_level_t level, const char *fmt, ...);
+#define do_debug(level, ...) \
+ _do_debug(level, __FILE__, __LINE__, __VA_ARGS__)
+
+void _do_debug(log_level_t level, const char *file, int line, const char *fmt, ...);
#endif
View
11 src/debug.c
@@ -21,21 +21,30 @@
void
-do_debug(log_level_t level, const char *fmt, ...)
+_do_debug(log_level_t level, const char *file, int line, const char *fmt, ...)
{
/* FIXME */
if (level >= conf.debug_level) {
time_t timep;
va_list argp;
+ char *timestr;
+ struct tm *local;
time(&timep);
+ local = localtime(&timep);
+ timestr = asctime(local);
+
+ fprintf(stderr, "[%.*s] %s:%d ",
+ strlen(timestr) - 1, timestr, file, line);
+
va_start(argp, fmt);
vfprintf(stderr, fmt, argp);
fflush(stderr);
va_end(argp);
}
if (level == LOG_FATAL) {
+ printf("\n");
exit(1);
}
}

0 comments on commit af5b293

Please sign in to comment.