[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 30/30] qga: use fixed-length and GDateTime for log timestamp
From: |
marcandre . lureau |
Subject: |
[PULL 30/30] qga: use fixed-length and GDateTime for log timestamp |
Date: |
Thu, 21 Apr 2022 17:49:40 +0400 |
From: Marc-André Lureau <marcandre.lureau@redhat.com>
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>
---
qga/main.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/qga/main.c b/qga/main.c
index 3c20bf1fbfe0..3b9546c18584 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);
}
}
--
2.36.0
- [PULL 20/30] tests: run-time skip test-qga if TSAN is enabled, (continued)
- [PULL 20/30] tests: run-time skip test-qga if TSAN is enabled, marcandre . lureau, 2022/04/21
- [PULL 21/30] Move error_printf_unless_qmp() with monitor unit, marcandre . lureau, 2022/04/21
- [PULL 22/30] qga: move qga_get_host_name(), marcandre . lureau, 2022/04/21
- [PULL 24/30] util: simplify write in signal handler, marcandre . lureau, 2022/04/21
- [PULL 23/30] qtest: simplify socket_send(), marcandre . lureau, 2022/04/21
- [PULL 25/30] util: use qemu_write_full() in qemu_write_pidfile(), marcandre . lureau, 2022/04/21
- [PULL 26/30] util: use qemu_create() in qemu_write_pidfile(), marcandre . lureau, 2022/04/21
- [PULL 27/30] util: replace qemu_get_local_state_pathname(), marcandre . lureau, 2022/04/21
- [PULL 28/30] qga: remove need for QEMU atomic.h, marcandre . lureau, 2022/04/21
- [PULL 29/30] tests/fuzz: fix warning, marcandre . lureau, 2022/04/21
- [PULL 30/30] qga: use fixed-length and GDateTime for log timestamp,
marcandre . lureau <=
- Re: [PULL 00/30] Misc patches, Richard Henderson, 2022/04/21