aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/log.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/util/log.c b/util/log.c
index 58d24de..abdcb6b 100644
--- a/util/log.c
+++ b/util/log.c
@@ -145,10 +145,28 @@ void qemu_log_unlock(FILE *logfile)
void qemu_log(const char *fmt, ...)
{
- FILE *f = qemu_log_trylock();
+ FILE *f;
+ g_autofree const char *timestr = NULL;
+
+ /*
+ * Prepare the timestamp *outside* the logging
+ * lock so it better reflects when the message
+ * was emitted if we are delayed acquiring the
+ * mutex
+ */
+ if (message_with_timestamp) {
+ g_autoptr(GDateTime) dt = g_date_time_new_now_utc();
+ timestr = g_date_time_format_iso8601(dt);
+ }
+
+ f = qemu_log_trylock();
if (f) {
va_list ap;
+ if (timestr) {
+ fprintf(f, "%s ", timestr);
+ }
+
va_start(ap, fmt);
vfprintf(f, fmt, ap);
va_end(ap);