]> git.ozlabs.org Git - petitboot/blobdiff - lib/log/log.c
lib/log: Include timestamp prefix
[petitboot] / lib / log / log.c
index a4f5c22adde5ba9f54263237acfe17bea3117852..adb207862b1c4a65286f6bb63aaf2b70ed76f99c 100644 (file)
@@ -1,6 +1,8 @@
 
 #include <assert.h>
 #include <stdarg.h>
+#include <stdlib.h>
+#include <time.h>
 
 #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);
 }
@@ -41,6 +52,11 @@ void __pb_log_init(FILE *fp, bool _debug)
        debug = _debug;
 }
 
+void pb_log_set_debug(bool _debug)
+{
+       debug = _debug;
+}
+
 FILE *pb_log_get_stream(void)
 {
        static FILE *null_stream;