* [PATCH] qga: use fixed-length and GDateTime for log timestamp
@ 2022-04-21 13:35 marcandre.lureau
2022-04-21 13:46 ` Daniel P. Berrangé
0 siblings, 1 reply; 2+ messages in thread
From: marcandre.lureau @ 2022-04-21 13:35 UTC (permalink / raw)
To: qemu-devel; +Cc: Marc-André Lureau, berrange, armbru, Michael Roth
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>
---
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.35.1.693.g805e0a68082a
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] qga: use fixed-length and GDateTime for log timestamp
2022-04-21 13:35 [PATCH] qga: use fixed-length and GDateTime for log timestamp marcandre.lureau
@ 2022-04-21 13:46 ` Daniel P. Berrangé
0 siblings, 0 replies; 2+ messages in thread
From: Daniel P. Berrangé @ 2022-04-21 13:46 UTC (permalink / raw)
To: marcandre.lureau; +Cc: Michael Roth, qemu-devel, armbru
On Thu, Apr 21, 2022 at 05:35:49PM +0400, marcandre.lureau@redhat.com wrote:
> 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>
> ---
> qga/main.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-04-21 13:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-21 13:35 [PATCH] qga: use fixed-length and GDateTime for log timestamp marcandre.lureau
2022-04-21 13:46 ` Daniel P. Berrangé
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.