Browse Source

Usability: Prefix logging to stdout with ISO 8601 formatted date and time in UTC

ppa-0.6.1
practicalswift 7 years ago
committed by Rusty Russell
parent
commit
3696e1b607
  1. 11
      lightningd/log.c

11
lightningd/log.c

@ -53,10 +53,17 @@ static void log_default_print(const char *prefix,
bool continued, bool continued,
const char *str, void *arg) 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) { if (!continued) {
printf("%s %s\n", prefix, str); printf("%s %s %s\n", iso8601_s, prefix, str);
} else { } else {
printf("%s \t%s\n", prefix, str); printf("%s %s \t%s\n", iso8601_s, prefix, str);
} }
fflush(stdout); fflush(stdout);
} }

Loading…
Cancel
Save