Skip to content

Commit

Permalink
improve debug infomation, add time/file/line info.
Browse files Browse the repository at this point in the history
  • Loading branch information
soarpenguin committed Feb 25, 2014
1 parent 22678bd commit af5b293
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion include/debug.h
Expand Up @@ -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
11 changes: 10 additions & 1 deletion src/debug.c
Expand Up @@ -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.