X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=lib%2Flog%2Flog.c;h=44543d03b4ce900368cbeb593e2f08feaf855059;hp=e006fd0b1495c34867648ae58ff047113de751a6;hb=7aa2d8a3aefc31c4503d8d9e361c791179894b34;hpb=dae4540e417e2bf72dd83b2713a670bde0056ba9 diff --git a/lib/log/log.c b/lib/log/log.c index e006fd0..44543d0 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -1,23 +1,58 @@ +#include #include #include "log.h" static FILE *logf; +static bool debug; + +static void __log(const char *fmt, va_list ap) +{ + if (!logf) + return; + vfprintf(logf, fmt, ap); + fflush(logf); +} void pb_log(const char *fmt, ...) { va_list ap; - FILE *stream; - - stream = logf ? logf : stdout; + va_start(ap, fmt); + __log(fmt, ap); + va_end(ap); +} +void pb_debug(const char *fmt, ...) +{ + va_list ap; + if (!debug) + return; va_start(ap, fmt); - vfprintf(stream, fmt, ap); + __log(fmt, ap); va_end(ap); } -void pb_log_set_stream(FILE *stream) +void __pb_log_init(FILE *fp, bool _debug) +{ + if (logf) + fflush(logf); + logf = fp; + debug = _debug; +} + +void pb_log_set_debug(bool _debug) +{ + debug = _debug; +} + +FILE *pb_log_get_stream(void) { - logf = stream; + static FILE *null_stream; + if (!logf) { + if (!null_stream) + null_stream = fopen("/dev/null", "a"); + return null_stream; + } + return logf; }