mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-19 05:44:12 +01:00
Usability: Prefix logging to stdout with ISO 8601 formatted date and time in UTC
This commit is contained in:
parent
d1ab2e05f4
commit
3696e1b607
@ -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…
Reference in New Issue
Block a user