X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=lib%2Flog%2Flog.c;h=7f14232443fd1538dc8454711b7a69f50b19c950;hp=0b145e0d3d6013f608935b3b696c3863e887c2a1;hb=HEAD;hpb=679d9dceb5bdf51f118548ca2645dc81088a8974;ds=sidebyside diff --git a/lib/log/log.c b/lib/log/log.c index 0b145e0..7f14232 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -9,7 +9,7 @@ static FILE *logf; static bool debug; -static void __log(const char *fmt, va_list ap) +static void __log_timestamp(void) { char hms[20] = {'\0'}; time_t t; @@ -17,10 +17,15 @@ static void __log(const char *fmt, va_list ap) if (!logf) return; - /* Add timestamp */ t = time(NULL); strftime(hms, sizeof(hms), "%T", localtime(&t)); fprintf(logf, "[%s] ", hms); +} + +static void __log(const char *fmt, va_list ap) +{ + if (!logf) + return; vfprintf(logf, fmt, ap); fflush(logf); @@ -30,6 +35,7 @@ void pb_log(const char *fmt, ...) { va_list ap; va_start(ap, fmt); + __log_timestamp(); __log(fmt, ap); va_end(ap); } @@ -49,6 +55,7 @@ void pb_debug(const char *fmt, ...) if (!debug) return; va_start(ap, fmt); + __log_timestamp(); __log(fmt, ap); va_end(ap); } @@ -88,6 +95,11 @@ void pb_log_set_debug(bool _debug) debug = _debug; } +bool pb_log_get_debug(void) +{ + return debug; +} + FILE *pb_log_get_stream(void) { static FILE *null_stream;