From 3696e1b60795b4d02559e1e0acb3e5a0143f2612 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Fri, 2 Feb 2018 10:35:41 +1030 Subject: [PATCH] Usability: Prefix logging to stdout with ISO 8601 formatted date and time in UTC --- lightningd/log.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lightningd/log.c b/lightningd/log.c index f25bcc86a..63ee1f7ba 100644 --- a/lightningd/log.c +++ b/lightningd/log.c @@ -53,10 +53,17 @@ static void log_default_print(const char *prefix, bool continued, const char *str, void *arg) { + struct timeval tv; + gettimeofday(&tv, NULL); + char iso8601_msec_fmt[sizeof("YYYY-mm-ddTHH:MM:SS.%03dZ")]; + strftime(iso8601_msec_fmt, sizeof(iso8601_msec_fmt), "%FT%T.%%03dZ", gmtime(&tv.tv_sec)); + char iso8601_s[sizeof("YYYY-mm-ddTHH:MM:SS.nnnZ")]; + snprintf(iso8601_s, sizeof(iso8601_s), iso8601_msec_fmt, (int) tv.tv_usec / 1000); + if (!continued) { - printf("%s %s\n", prefix, str); + printf("%s %s %s\n", iso8601_s, prefix, str); } else { - printf("%s \t%s\n", prefix, str); + printf("%s %s \t%s\n", iso8601_s, prefix, str); } fflush(stdout); }