pb_log: Break out timestamp
authorGeoff Levand <geoff@infradead.org>
Mon, 13 Aug 2018 16:23:07 +0000 (09:23 -0700)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Tue, 14 Aug 2018 01:10:07 +0000 (11:10 +1000)
Fixes double timestamp on pb_log_fn, pb_debug_fn.

Signed-off-by: Geoff Levand <geoff@infradead.org>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
lib/log/log.c

index 5466d817575277ab32f7a827f822cb36ccc08965..7f14232443fd1538dc8454711b7a69f50b19c950 100644 (file)
@@ -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);
 }