summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>2018-07-30 11:48:24 +1000
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>2018-07-30 14:17:05 +1000
commitb0c603d007174e75452c1c14402d62d305da76ab (patch)
treee137b2a088f9865194b245973ba288e267e365f6 /lib
parenta30e4ac8a8e38f9b972bf6670f91b0e372e00777 (diff)
downloadtalos-petitboot-b0c603d007174e75452c1c14402d62d305da76ab.zip
talos-petitboot-b0c603d007174e75452c1c14402d62d305da76ab.tar.gz
lib/log: Include timestamp prefix
The relative time between logged events is very useful during debugging, particularly when debugging autoboot failures. Prepend a short HH:MM:SS timestamp to each line logged. Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/log/log.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/log/log.c b/lib/log/log.c
index 44543d0..adb2078 100644
--- a/lib/log/log.c
+++ b/lib/log/log.c
@@ -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);
}
OpenPOWER on IntegriCloud