log: Make glib logging go through QEMU
PATCH v2 1/1 log: Make glib logging go through QEMU
This commit adds a qemu_init_logging() 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 monitor if one is configured.
This commit also adds a call to qemu_init_logging() to the binaries installed by QEMU.
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.
---
Changes since v1:
- introduced a qemu_init_logging() helper, and call that in more binaries than just vl.c
bsd-user/main.c | 1 + include/qemu/error-report.h | 2 ++ linux-user/main.c | 1 + qemu-img.c | 1 + qemu-io.c | 1 + qemu-nbd.c | 1 + scsi/qemu-pr-helper.c | 1 + util/qemu-error.c | 33 +++++++++++++++++++++++++++++++++ vl.c | 1 + 9 files changed, 42 insertions(+)
bsd-user/main.c +1 -0
@@ -743,6 +743,7 @@ int main(int argc, char **argv)if (argc <=1 )usage (); +qemu_init_logging ();module_call_init (MODULE_INIT_TRACE );qemu_init_cpu_list ();module_call_init (MODULE_INIT_QOM );
include/qemu/error-report.h +2 -0
@@ -49,6 +49,8 @@ bool error_report_once_cond(bool *printed, const char *fmt, ...) bool warn_report_once_cond(bool *printed, const char *fmt, ...) GCC_FMT_ATTR(2, 3); +void qemu_init_logging (void ); +/* * Similar to error_report(), except it prints the message just once. * Return true when it prints, false otherwise.
linux-user/main.c +1 -0
@@ -600,6 +600,7 @@ int main(int argc, char **argv, char **envp)int ret;int execfd; +qemu_init_logging ();module_call_init (MODULE_INIT_TRACE );qemu_init_cpu_list ();module_call_init (MODULE_INIT_QOM );
qemu-img.c +1 -0
@@ -4912,6 +4912,7 @@ int main(int argc, char **argv)signal (SIGPIPE ,SIG_IGN );#endif +qemu_init_logging ();module_call_init (MODULE_INIT_TRACE );error_set_progname (argv[0 ]);qemu_init_exec_dir (argv[0 ]);
qemu-io.c +1 -0
@@ -524,6 +524,7 @@ int main(int argc, char **argv)signal (SIGPIPE ,SIG_IGN );#endif +qemu_init_logging ();module_call_init (MODULE_INIT_TRACE ); progname =g_path_get_basename (argv[0 ]);qemu_init_exec_dir (argv[0 ]);
qemu-nbd.c +1 -0
@@ -570,6 +570,7 @@ int main(int argc, char **argv)signal (SIGPIPE ,SIG_IGN );#endif +qemu_init_logging ();module_call_init (MODULE_INIT_TRACE );qcrypto_init (&error_fatal);
scsi/qemu-pr-helper.c +1 -0
@@ -895,6 +895,7 @@ int main(int argc, char **argv)signal (SIGPIPE ,SIG_IGN ); +qemu_init_logging ();module_call_init (MODULE_INIT_TRACE );module_call_init (MODULE_INIT_QOM );qemu_add_opts (&qemu_trace_opts);
util/qemu-error.c +33 -0
@@ -345,3 +345,36 @@ bool warn_report_once_cond(bool *printed, const char *fmt, ...)va_end (ap);return true; } + +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 : +break ; +case G_LOG_LEVEL_INFO : +/* Fall through */ +case G_LOG_LEVEL_MESSAGE : +info_report ("%s" , message); +break ; +case G_LOG_LEVEL_WARNING : +/* Fall through */ +case G_LOG_LEVEL_CRITICAL : +warn_report ("%s" , message); +break ; +case G_LOG_LEVEL_ERROR : +error_report ("%s" , message); +break ; + } +} + +/* +* Init QEMU logging subsystem. This sets up glib logging so libraries using it +* also print their logs through {info,warn,error}_report. +*/ +void qemu_init_logging (void ) +{ +g_log_set_default_handler (qemu_log_func,NULL ); +}
vl.c +1 -0
@@ -3015,6 +3015,7 @@ int main(int argc, char **argv, char **envp) QSIMPLEQ_HEAD(, BlockdevOptions_queue) bdo_queue =QSIMPLEQ_HEAD_INITIALIZER (bdo_queue); +qemu_init_logging ();module_call_init (MODULE_INIT_TRACE );qemu_init_cpu_list ();
Signature · 1 line
2.19.2
Quoted 27 lines · Christophe Fergeau
This commit adds a
qemu_init_logging()helper which callsg_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 monitor if one is configured.
This commit also adds a call toqemu_init_logging()to the binaries installed by QEMU.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 <[email protected]>---
Changes since v1:
- introduced aqemu_init_logging()helper, and call that in more binaries than justvl.cutil/qemu-error.c +8
-0+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 : +break ;
util/qemu-error.c bool warn_report_once_cond(bool *printed, const char *fmt, ...) · line 366
Quoted 10 lines
util/qemu-error.c +10
-0+case G_LOG_LEVEL_INFO : +/* Fall through */ +case G_LOG_LEVEL_MESSAGE : +info_report ("%s" , message); +break ; +case G_LOG_LEVEL_WARNING : +/* Fall through */ +case G_LOG_LEVEL_CRITICAL : +warn_report ("%s" , message); +break ;
This didn't adress my previous comment that _CRITICAL should do an error_report, not warn_reoprt.
util/qemu-error.c bool warn_report_once_cond(bool *printed, const char *fmt, ...) · line 371
Quoted 5 lines
util/qemu-error.c +5
-0+case G_LOG_LEVEL_ERROR : +error_report ("%s" , message); +break ; + } +}
Regards,
Daniel
Signature · 3 lines
|: 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 :|
Quoted 33 lines · Daniel P. Berrangé
Quoted 32 lines · Christophe Fergeau
This commit adds a
qemu_init_logging()helper which callsg_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 monitor if one is configured.
This commit also adds a call toqemu_init_logging()to the binaries installed by QEMU.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 <[email protected]>---
Changes since v1:
- introduced aqemu_init_logging()helper, and call that in more binaries than justvl.cutil/qemu-error.c +13
-0+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 : +break ; +case G_LOG_LEVEL_INFO : +/* Fall through */ +case G_LOG_LEVEL_MESSAGE : +info_report ("%s" , message); +break ;
Quoted 8 lines
util/qemu-error.c bool warn_report_once_cond(bool *printed, const char *fmt, ...) · line 366
Quoted 5 lines
util/qemu-error.c +5
-0+case G_LOG_LEVEL_WARNING : +/* Fall through */ +case G_LOG_LEVEL_CRITICAL : +warn_report ("%s" , message); +break ;This didn't adress my previous comment that
_CRITICALshould do anerror_report, notwarn_reoprt.
My bad, sorry for missing it, v3 incoming.
Christophe