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
This commit is contained in:
Jonathan Lebon 2016-08-18 12:10:20 -04:00 committed by Atomic Bot
parent 8d9d3a1d4a
commit bfa8eaccd3

View File

@ -77,9 +77,15 @@ httpd_log (OtTrivialHttpd *httpd, const gchar *format, ...)
if (!httpd->log) if (!httpd->log)
return; 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); va_start (args, format);
g_string_vprintf (str, format, args); g_string_append_vprintf (str, format, args);
va_end (args); va_end (args);
g_output_stream_write_all (httpd->log, str->str, str->len, &written, NULL, NULL); g_output_stream_write_all (httpd->log, str->str, str->len, &written, NULL, NULL);