Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Merged
merged 1 commit into from

1 participant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 28, 2014
This page is out of date. Refresh to see the latest.
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,14 +21,22 @@
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);
@@ -36,6 +44,7 @@ do_debug(log_level_t level, const char *fmt, ...)
}
if (level == LOG_FATAL) {
+ fprintf(stderr, "\n");
exit(1);
}
}
Something went wrong with that request. Please try again.