summaryrefslogtreecommitdiffstats
path: root/qga
diff options
context:
space:
mode:
authorMarc-André Lureau2022-04-07 13:21:41 +0200
committerMarc-André Lureau2022-04-21 15:37:16 +0200
commit55fa0170721e827c1701db3a66a54d44b5660d53 (patch)
tree16e06b312b5500fa670e17901702205d225bc0ce /qga
parenttests/fuzz: fix warning (diff)
downloadqemu-55fa0170721e827c1701db3a66a54d44b5660d53.tar.gz
qemu-55fa0170721e827c1701db3a66a54d44b5660d53.tar.xz
qemu-55fa0170721e827c1701db3a66a54d44b5660d53.zip
qga: use fixed-length and GDateTime for log timestamp
The old code is kind of wrong. Say it's 1649309843.000001 seconds past the epoch. Prints "1649309843.1". 9us later, it prints "1649309843.10". Should really use %06lu for the microseconds part. Use GDateTime instead, as suggested by Daniel. Suggested-by: Markus Armbruster <armbru@redhat.com> Suggested-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Diffstat (limited to 'qga')
-rw-r--r--qga/main.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/qga/main.c b/qga/main.c
index 3c20bf1fbf..3b9546c185 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -328,11 +328,9 @@ static void ga_log(const gchar *domain, GLogLevelFlags level,
#else
if (level & s->log_level) {
#endif
- gint64 t = g_get_real_time();
- fprintf(s->log_file,
- "%" G_GINT64_FORMAT ".%" G_GINT64_FORMAT
- ": %s: %s\n", t / G_USEC_PER_SEC, t % G_USEC_PER_SEC,
- level_str, msg);
+ g_autoptr(GDateTime) now = g_date_time_new_now_utc();
+ g_autofree char *nowstr = g_date_time_format(now, "%s.%f");
+ fprintf(s->log_file, "%s: %s: %s\n", nowstr, level_str, msg);
fflush(s->log_file);
}
}