From bfa8eaccd30ff9c24a8c8d36c907879e44eb95a3 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Thu, 18 Aug 2016 12:10:20 -0400 Subject: [PATCH] trivial-httpd: prepend timestamp in log file I've found this useful when monitoring multiple logs at the same time to test the upcoming content & meta URL splitting. Closes: #469 Approved by: cgwalters --- src/ostree/ot-builtin-trivial-httpd.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ostree/ot-builtin-trivial-httpd.c b/src/ostree/ot-builtin-trivial-httpd.c index 30c593c2..88a1a74b 100644 --- a/src/ostree/ot-builtin-trivial-httpd.c +++ b/src/ostree/ot-builtin-trivial-httpd.c @@ -77,9 +77,15 @@ httpd_log (OtTrivialHttpd *httpd, const gchar *format, ...) if (!httpd->log) return; - str = g_string_new (NULL); + { + g_autoptr(GDateTime) now = g_date_time_new_now_local (); + g_autofree char *timestamp = g_date_time_format (now, "%F %T"); + str = g_string_new (timestamp); + g_string_append_printf (str, ".%06d - ", g_date_time_get_microsecond (now)); + } + va_start (args, format); - g_string_vprintf (str, format, args); + g_string_append_vprintf (str, format, args); va_end (args); g_output_stream_write_all (httpd->log, str->str, str->len, &written, NULL, NULL);