X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=lib%2Flog%2Flog.c;h=5466d817575277ab32f7a827f822cb36ccc08965;hp=a4f5c22adde5ba9f54263237acfe17bea3117852;hb=a915889b7fbbc4be11f9a37ea7afb5b3f3d41173;hpb=b08de841267546726f452c89cc326a493ec6549c diff --git a/lib/log/log.c b/lib/log/log.c index a4f5c22..5466d81 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -1,6 +1,8 @@ #include #include +#include +#include #include "log.h" @@ -9,8 +11,17 @@ static bool debug; static void __log(const char *fmt, va_list ap) { + char hms[20] = {'\0'}; + time_t t; + if (!logf) return; + + /* Add timestamp */ + t = time(NULL); + strftime(hms, sizeof(hms), "%T", localtime(&t)); + fprintf(logf, "[%s] ", hms); + vfprintf(logf, fmt, ap); fflush(logf); } @@ -23,6 +34,15 @@ void pb_log(const char *fmt, ...) va_end(ap); } +void _pb_log_fn(const char *func, const char *fmt, ...) +{ + va_list ap; + pb_log("%s: ", func); + va_start(ap, fmt); + __log(fmt, ap); + va_end(ap); +} + void pb_debug(const char *fmt, ...) { va_list ap; @@ -33,6 +53,28 @@ void pb_debug(const char *fmt, ...) va_end(ap); } +void _pb_debug_fn(const char *func, const char *fmt, ...) +{ + va_list ap; + if (!debug) + return; + pb_log("%s: ", func); + va_start(ap, fmt); + __log(fmt, ap); + va_end(ap); +} + +void _pb_debug_fl(const char *func, int line, const char *fmt, ...) +{ + va_list ap; + if (!debug) + return; + pb_log("%s:%d: ", func, line); + va_start(ap, fmt); + __log(fmt, ap); + va_end(ap); +} + void __pb_log_init(FILE *fp, bool _debug) { if (logf) @@ -41,6 +83,16 @@ void __pb_log_init(FILE *fp, bool _debug) debug = _debug; } +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;