Permalink
Browse files

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

  • Loading branch information...
1 parent 6affda6 commit 768b407150eaaf1f1033e902bd94c4f8afb3d8d3 @soarpenguin committed Feb 28, 2014
Showing with 14 additions and 2 deletions.
  1. +4 −1 include/debug.h
  2. +10 −1 src/debug.c
View
@@ -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
@@ -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 ",
+ (int)(strlen(timestr) - 1), timestr, file, line);
+
va_start(argp, fmt);
vfprintf(stderr, fmt, argp);
fflush(stderr);
va_end(argp);
}
if (level == LOG_FATAL) {
+ fprintf(stderr, "\n");
exit(1);
}
}

0 comments on commit 768b407

Please sign in to comment.