From: Mario Smarduch <msmarduch@digitalocean.com>
To: philmd@redhat.com, mtosatti@redhat.com, pbonzini@redhat.com,
armbru@redhat.com
Cc: qemu-devel@nongnu.org, qemu-trivial@nongnu.org, rth@twiddle.net,
ehabkost@redhat.com, Mario Smarduch <msmarduch@digitalocean.com>
Subject: [PATCHv2 1/2] util/qemu-error: add guest name helper with -msg options
Date: Wed, 9 Oct 2019 09:44:58 -0700 [thread overview]
Message-ID: <20191009164459.8209-2-msmarduch@digitalocean.com> (raw)
In-Reply-To: <20191009164459.8209-1-msmarduch@digitalocean.com>
This patch adds an option to enable/disable printing lead guest name in
logging messages.
A '-msg name=on|off' allows to turn on, off guest name logging.
If guest name is not set disabling this makes sense.
Verified with all combinations of
'-msg timestamp=yes|no,name=yes|no.
Signed-off-by: Mario Smarduch <msmarduch@digitalocean.com>
---
include/qemu/error-report.h | 1 +
qemu-options.hx | 10 ++++++----
util/qemu-error.c | 31 +++++++++++++++++++++++++++++++
vl.c | 5 +++++
4 files changed, 43 insertions(+), 4 deletions(-)
diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
index 00d069b..9b44a06 100644
--- a/include/qemu/error-report.h
+++ b/include/qemu/error-report.h
@@ -74,5 +74,6 @@ void error_init(const char *argv0);
const char *error_get_progname(void);
extern bool enable_timestamp_msg;
+extern bool enable_guestname_msg;
#endif
diff --git a/qemu-options.hx b/qemu-options.hx
index 2a04ca6..6066001 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -4164,14 +4164,16 @@ HXCOMM Deprecated by -accel tcg
DEF("no-kvm", 0, QEMU_OPTION_no_kvm, "", QEMU_ARCH_I386)
DEF("msg", HAS_ARG, QEMU_OPTION_msg,
- "-msg timestamp[=on|off]\n"
+ "-msg [timestamp=on|off][name=on|off]\n"
" change the format of messages\n"
- " on|off controls leading timestamps (default:on)\n",
+ " timestamp=on|off controls leading timestamps (default: on)\n"
+ " name=on|off controls leading guest name (default: off)\n",
QEMU_ARCH_ALL)
STEXI
-@item -msg timestamp[=on|off]
+@item -msg timestamp=on|off
+@item -msg name=on|off
@findex -msg
-prepend a timestamp to each log message.(default:on)
+Prepend additional information to each log message
ETEXI
DEF("dump-vmstate", HAS_ARG, QEMU_OPTION_dump_vmstate,
diff --git a/util/qemu-error.c b/util/qemu-error.c
index f373f3b..8ece7b2 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -11,6 +11,8 @@
*/
#include "qemu/osdep.h"
+#include "qemu/option.h"
+#include "qemu/config-file.h"
#include "monitor/monitor.h"
#include "qemu/error-report.h"
@@ -192,6 +194,8 @@ static void print_loc(void)
}
bool enable_timestamp_msg;
+bool enable_guestname_msg;
+
/*
* Print a message to current monitor if we have one, else to stderr.
* @report_type is the type of message: error, warning or informational.
@@ -228,6 +232,27 @@ static void vreport(report_type type, const char *fmt, va_list ap)
error_printf("\n");
}
+static const char *error_get_guestname(void)
+{
+ QemuOpts *opts = qemu_opts_find(qemu_find_opts("name"), NULL);
+ return qemu_opt_get(opts, "guest");
+}
+
+/*
+ * Also print the guest name, handy if we log to a server.
+ */
+static void error_print_guestname(void)
+{
+ const char *name;
+
+ if (enable_guestname_msg) {
+ name = error_get_guestname();
+ if (name && !cur_mon) {
+ error_printf("Guest [%s] ", name);
+ }
+ }
+}
+
/*
* Print an error message to current monitor if we have one, else to stderr.
* Format arguments like vsprintf(). The resulting message should be
@@ -237,6 +262,7 @@ static void vreport(report_type type, const char *fmt, va_list ap)
*/
void error_vreport(const char *fmt, va_list ap)
{
+ error_print_guestname();
vreport(REPORT_TYPE_ERROR, fmt, ap);
}
@@ -248,6 +274,7 @@ void error_vreport(const char *fmt, va_list ap)
*/
void warn_vreport(const char *fmt, va_list ap)
{
+ error_print_guestname();
vreport(REPORT_TYPE_WARNING, fmt, ap);
}
@@ -274,6 +301,7 @@ void error_report(const char *fmt, ...)
{
va_list ap;
+ error_print_guestname();
va_start(ap, fmt);
vreport(REPORT_TYPE_ERROR, fmt, ap);
va_end(ap);
@@ -289,6 +317,7 @@ void warn_report(const char *fmt, ...)
{
va_list ap;
+ error_print_guestname();
va_start(ap, fmt);
vreport(REPORT_TYPE_WARNING, fmt, ap);
va_end(ap);
@@ -324,6 +353,7 @@ bool error_report_once_cond(bool *printed, const char *fmt, ...)
return false;
}
*printed = true;
+ error_print_guestname();
va_start(ap, fmt);
vreport(REPORT_TYPE_ERROR, fmt, ap);
va_end(ap);
@@ -344,6 +374,7 @@ bool warn_report_once_cond(bool *printed, const char *fmt, ...)
return false;
}
*printed = true;
+ error_print_guestname();
va_start(ap, fmt);
vreport(REPORT_TYPE_WARNING, fmt, ap);
va_end(ap);
diff --git a/vl.c b/vl.c
index 002bf49..024bdc6 100644
--- a/vl.c
+++ b/vl.c
@@ -417,6 +417,10 @@ static QemuOptsList qemu_msg_opts = {
.name = "timestamp",
.type = QEMU_OPT_BOOL,
},
+ {
+ .name = "name",
+ .type = QEMU_OPT_BOOL,
+ },
{ /* end of list */ }
},
};
@@ -1263,6 +1267,7 @@ static void realtime_init(void)
static void configure_msg(QemuOpts *opts)
{
enable_timestamp_msg = qemu_opt_get_bool(opts, "timestamp", true);
+ enable_guestname_msg = qemu_opt_get_bool(opts, "name", false);
}
--
2.9.3
next prev parent reply other threads:[~2019-10-09 19:59 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-09 16:44 [PATCHv2 0/2] log guest name and memory error type AO, AR for MCEs Mario Smarduch
2019-10-09 16:44 ` Mario Smarduch [this message]
2019-10-09 21:16 ` [PATCHv2 1/2] util/qemu-error: add guest name helper with -msg options Paolo Bonzini
2019-10-10 7:02 ` Markus Armbruster
2019-10-10 8:16 ` Markus Armbruster
2019-10-10 11:25 ` Paolo Bonzini
2019-10-09 16:44 ` [PATCHv2 2/2] target/i386: log MCE guest and host addresses Mario Smarduch
2019-10-09 21:19 ` [PATCHv2 0/2] log guest name and memory error type AO, AR for MCEs Paolo Bonzini
2019-10-09 23:01 ` Mario Smarduch
2019-10-09 22:55 ` no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191009164459.8209-2-msmarduch@digitalocean.com \
--to=msmarduch@digitalocean.com \
--cc=armbru@redhat.com \
--cc=ehabkost@redhat.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=rth@twiddle.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).