[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/2] util/log: add timestamp to logs via qemu_log()
From: |
Dongli Zhang |
Subject: |
[PATCH 2/2] util/log: add timestamp to logs via qemu_log() |
Date: |
Mon, 29 Aug 2022 03:06:22 -0700 |
The qemu_log is very helpful for diagnostic. Add the timestamp to the log
when it is enabled (e.g., "-msg timestamp=on").
While there are many other places that may print to log file, this patch is
only for qemu_log(), e.g., the developer may add qemu_log/qemu_log_mask to
selected locations to diagnose QEMU issue.
Cc: Joe Jin <joe.jin@oracle.com>
Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
---
Please let me know if we should use 'error_with_guestname' as well.
util/log.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/util/log.c b/util/log.c
index d6eb037..f0a081a 100644
--- a/util/log.c
+++ b/util/log.c
@@ -129,8 +129,15 @@ void qemu_log(const char *fmt, ...)
{
FILE *f = qemu_log_trylock();
if (f) {
+ gchar *timestr;
va_list ap;
+ if (message_with_timestamp) {
+ timestr = real_time_iso8601();
+ fprintf(f, "%s ", timestr);
+ g_free(timestr);
+ }
+
va_start(ap, fmt);
vfprintf(f, fmt, ap);
va_end(ap);
--
1.8.3.1