cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
218e99
From d654202a62b8bf07cba4044e4eb912958c7392bb Mon Sep 17 00:00:00 2001
218e99
From: Laszlo Ersek <lersek@redhat.com>
218e99
Date: Wed, 28 Aug 2013 15:50:44 +0200
218e99
Subject: [PATCH 27/28] add timestamp to error_report()
218e99
218e99
RH-Author: Laszlo Ersek <lersek@redhat.com>
218e99
Message-id: <1377705045-1054-2-git-send-email-lersek@redhat.com>
218e99
Patchwork-id: 53886
218e99
O-Subject: [RHEL-7 qemu-kvm PATCH v3 1/2] add timestamp to error_report()
218e99
Bugzilla: 906937
218e99
RH-Acked-by: Michal Novotny <minovotn@redhat.com>
218e99
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
218e99
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
218e99
From: Seiji Aguchi <seiji.aguchi@hds.com>
218e99
218e99
[Issue]
218e99
When we offer a customer support service and a problem happens
218e99
in a customer's system, we try to understand the problem by
218e99
comparing what the customer reports with message logs of the
218e99
customer's system.
218e99
218e99
In this case, we often need to know when the problem happens.
218e99
218e99
But, currently, there is no timestamp in qemu's error messages.
218e99
Therefore, we may not be able to understand the problem based on
218e99
error messages.
218e99
218e99
[Solution]
218e99
Add a timestamp to qemu's error message logged by
218e99
error_report() with g_time_val_to_iso8601().
218e99
218e99
Signed-off-by: Seiji Aguchi <seiji.aguchi@hds.com>
218e99
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
218e99
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
218e99
(cherry picked from commit 5e2ac5191772dea782ff78e95edd395985273019)
218e99
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
218e99
---
218e99
 include/qemu/error-report.h |    2 ++
218e99
 util/qemu-error.c           |   10 ++++++++++
218e99
 vl.c                        |   26 ++++++++++++++++++++++++++
218e99
 qemu-options.hx             |   11 +++++++++++
218e99
 4 files changed, 49 insertions(+), 0 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 include/qemu/error-report.h |    2 ++
218e99
 qemu-options.hx             |   11 +++++++++++
218e99
 util/qemu-error.c           |   10 ++++++++++
218e99
 vl.c                        |   26 ++++++++++++++++++++++++++
218e99
 4 files changed, 49 insertions(+), 0 deletions(-)
218e99
218e99
diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
218e99
index 14c1719..3b098a9 100644
218e99
--- a/include/qemu/error-report.h
218e99
+++ b/include/qemu/error-report.h
218e99
@@ -14,6 +14,7 @@
218e99
 #define QEMU_ERROR_H
218e99
 
218e99
 #include <stdarg.h>
218e99
+#include <stdbool.h>
218e99
 #include "qemu/compiler.h"
218e99
 
218e99
 typedef struct Location {
218e99
@@ -40,5 +41,6 @@ void error_print_loc(void);
218e99
 void error_set_progname(const char *argv0);
218e99
 void error_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
218e99
 const char *error_get_progname(void);
218e99
+extern bool enable_timestamp_msg;
218e99
 
218e99
 #endif
218e99
diff --git a/qemu-options.hx b/qemu-options.hx
218e99
index fb62b75..2ad0ed2 100644
218e99
--- a/qemu-options.hx
218e99
+++ b/qemu-options.hx
218e99
@@ -3095,6 +3095,17 @@ property must be set.  These objects are placed in the
218e99
 '/objects' path.
218e99
 ETEXI
218e99
 
218e99
+DEF("msg", HAS_ARG, QEMU_OPTION_msg,
218e99
+    "-msg timestamp[=on|off]\n"
218e99
+    "                change the format of messages\n"
218e99
+    "                on|off controls leading timestamps (default:on)\n",
218e99
+    QEMU_ARCH_ALL)
218e99
+STEXI
218e99
+@item -msg timestamp[=on|off]
218e99
+@findex -msg
218e99
+prepend a timestamp to each log message.(default:on)
218e99
+ETEXI
218e99
+
218e99
 HXCOMM This is the last statement. Insert new options before this line!
218e99
 STEXI
218e99
 @end table
218e99
diff --git a/util/qemu-error.c b/util/qemu-error.c
218e99
index 08a36f4..fec02c6 100644
218e99
--- a/util/qemu-error.c
218e99
+++ b/util/qemu-error.c
218e99
@@ -196,6 +196,7 @@ void error_print_loc(void)
218e99
     }
218e99
 }
218e99
 
218e99
+bool enable_timestamp_msg;
218e99
 /*
218e99
  * Print an error message to current monitor if we have one, else to stderr.
218e99
  * Format arguments like sprintf().  The result should not contain
218e99
@@ -206,6 +207,15 @@ void error_print_loc(void)
218e99
 void error_report(const char *fmt, ...)
218e99
 {
218e99
     va_list ap;
218e99
+    GTimeVal tv;
218e99
+    gchar *timestr;
218e99
+
218e99
+    if (enable_timestamp_msg) {
218e99
+        g_get_current_time(&tv;;
218e99
+        timestr = g_time_val_to_iso8601(&tv;;
218e99
+        error_printf("%s ", timestr);
218e99
+        g_free(timestr);
218e99
+    }
218e99
 
218e99
     error_print_loc();
218e99
     va_start(ap, fmt);
218e99
diff --git a/vl.c b/vl.c
218e99
index d424af7..0ce554d 100644
218e99
--- a/vl.c
218e99
+++ b/vl.c
218e99
@@ -518,6 +518,18 @@ static QemuOptsList qemu_realtime_opts = {
218e99
     },
218e99
 };
218e99
 
218e99
+static QemuOptsList qemu_msg_opts = {
218e99
+    .name = "msg",
218e99
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_msg_opts.head),
218e99
+    .desc = {
218e99
+        {
218e99
+            .name = "timestamp",
218e99
+            .type = QEMU_OPT_BOOL,
218e99
+        },
218e99
+        { /* end of list */ }
218e99
+    },
218e99
+};
218e99
+
218e99
 /**
218e99
  * Get machine options
218e99
  *
218e99
@@ -1473,6 +1485,12 @@ static void configure_realtime(QemuOpts *opts)
218e99
     }
218e99
 }
218e99
 
218e99
+
218e99
+static void configure_msg(QemuOpts *opts)
218e99
+{
218e99
+    enable_timestamp_msg = qemu_opt_get_bool(opts, "timestamp", true);
218e99
+}
218e99
+
218e99
 /***********************************************************/
218e99
 /* USB devices */
218e99
 
218e99
@@ -2911,6 +2929,7 @@ int main(int argc, char **argv, char **envp)
218e99
     qemu_add_opts(&qemu_object_opts);
218e99
     qemu_add_opts(&qemu_tpmdev_opts);
218e99
     qemu_add_opts(&qemu_realtime_opts);
218e99
+    qemu_add_opts(&qemu_msg_opts);
218e99
 
218e99
     runstate_init();
218e99
 
218e99
@@ -3883,6 +3902,13 @@ int main(int argc, char **argv, char **envp)
218e99
                 }
218e99
                 configure_realtime(opts);
218e99
                 break;
218e99
+            case QEMU_OPTION_msg:
218e99
+                opts = qemu_opts_parse(qemu_find_opts("msg"), optarg, 0);
218e99
+                if (!opts) {
218e99
+                    exit(1);
218e99
+                }
218e99
+                configure_msg(opts);
218e99
+                break;
218e99
             default:
218e99
                 os_parse_cmd_args(popt->index, optarg);
218e99
             }
218e99
-- 
218e99
1.7.1
218e99