mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-06 01:03:55 -06:00
log: Make glib logging go through QEMU
This commit adds a error_init() helper which calls g_log_set_default_handler() so that glib logs (g_log, g_warning, ...) are handled similarly to other QEMU logs. This means they will get a timestamp if timestamps are enabled, and they will go through the HMP monitor if one is configured. This commit also adds a call to error_init() to the binaries installed by QEMU. Since error_init() also calls error_set_progname(), this means that *-linux-user, *-bsd-user and qemu-pr-helper messages output with error_report, info_report, ... will slightly change: they will be prefixed by the binary name. glib debug messages are enabled through G_MESSAGES_DEBUG similarly to the glib default log handler. At the moment, this change will mostly impact SPICE logging if your spice version is >= 0.14.1. With older spice versions, this is not going to work as expected, but will not have any ill effect, so this call is not conditional on the SPICE version. Signed-off-by: Christophe Fergeau <cfergeau@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20190131164614.19209-3-cfergeau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
99e98d7c9f
commit
f5852efa29
9 changed files with 65 additions and 6 deletions
|
@ -142,7 +142,7 @@ static const char *progname;
|
|||
/*
|
||||
* Set the program name for error_print_loc().
|
||||
*/
|
||||
void error_set_progname(const char *argv0)
|
||||
static void error_set_progname(const char *argv0)
|
||||
{
|
||||
const char *p = strrchr(argv0, '/');
|
||||
progname = p ? p + 1 : argv0;
|
||||
|
@ -345,3 +345,56 @@ bool warn_report_once_cond(bool *printed, const char *fmt, ...)
|
|||
va_end(ap);
|
||||
return true;
|
||||
}
|
||||
|
||||
static char *qemu_glog_domains;
|
||||
|
||||
static void qemu_log_func(const gchar *log_domain,
|
||||
GLogLevelFlags log_level,
|
||||
const gchar *message,
|
||||
gpointer user_data)
|
||||
{
|
||||
switch (log_level & G_LOG_LEVEL_MASK) {
|
||||
case G_LOG_LEVEL_DEBUG:
|
||||
case G_LOG_LEVEL_INFO:
|
||||
/*
|
||||
* Use same G_MESSAGES_DEBUG logic as glib to enable/disable debug
|
||||
* messages
|
||||
*/
|
||||
if (qemu_glog_domains == NULL) {
|
||||
break;
|
||||
}
|
||||
if (strcmp(qemu_glog_domains, "all") != 0 &&
|
||||
(log_domain == NULL || !strstr(qemu_glog_domains, log_domain))) {
|
||||
break;
|
||||
}
|
||||
/* Fall through */
|
||||
case G_LOG_LEVEL_MESSAGE:
|
||||
info_report("%s%s%s",
|
||||
log_domain ?: "", log_domain ? ": " : "", message);
|
||||
|
||||
break;
|
||||
case G_LOG_LEVEL_WARNING:
|
||||
warn_report("%s%s%s",
|
||||
log_domain ?: "", log_domain ? ": " : "", message);
|
||||
break;
|
||||
case G_LOG_LEVEL_CRITICAL:
|
||||
case G_LOG_LEVEL_ERROR:
|
||||
error_report("%s%s%s",
|
||||
log_domain ?: "", log_domain ? ": " : "", message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void error_init(const char *argv0)
|
||||
{
|
||||
/* Set the program name for error_print_loc(). */
|
||||
error_set_progname(argv0);
|
||||
|
||||
/*
|
||||
* This sets up glib logging so libraries using it also print their logs
|
||||
* through error_report(), warn_report(), info_report().
|
||||
*/
|
||||
g_log_set_default_handler(qemu_log_func, NULL);
|
||||
g_warn_if_fail(qemu_glog_domains == NULL);
|
||||
qemu_glog_domains = g_strdup(g_getenv("G_MESSAGES_DEBUG"));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue