Re: [Qemu-devel] [PATCH v6 2/2] log: Make glib logging go through QEMU

2019-01-29 Thread Markus Armbruster
Christophe Fergeau  writes:

> 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
> HMP monitor if one is configured.
> This commit also adds a call to qemu_init_logging() to the binaries
> installed by QEMU.
> glib debug messages are enabled through G_MESSAGES_DEBUG similarly to
> 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 
> ---
>  bsd-user/main.c |  2 ++
>  include/qemu/error-report.h |  3 ++-
>  linux-user/main.c   |  2 ++
>  qemu-img.c  |  2 +-
>  qemu-io.c   |  2 +-
>  qemu-nbd.c  |  2 +-
>  scsi/qemu-pr-helper.c   |  1 +
>  util/qemu-error.c   | 48 -
>  vl.c|  2 +-
>  9 files changed, 58 insertions(+), 6 deletions(-)
>
> diff --git a/bsd-user/main.c b/bsd-user/main.c
> index 0d3156974c..8fd8ae4127 100644
> --- a/bsd-user/main.c
> +++ b/bsd-user/main.c
> @@ -24,6 +24,7 @@
>  #include "qapi/error.h"
>  #include "qemu.h"
>  #include "qemu/config-file.h"
> +#include "qemu/error-report.h"
>  #include "qemu/path.h"
>  #include "qemu/help_option.h"
>  #include "cpu.h"
> @@ -743,6 +744,7 @@ int main(int argc, char **argv)
>  if (argc <= 1)
>  usage();
>  
> +error_init(argv[0]);
>  module_call_init(MODULE_INIT_TRACE);
>  qemu_init_cpu_list();
>  module_call_init(MODULE_INIT_QOM);

This changes output of error_report() & friends in this program.
Probably in a good way.  Should it be a separate commit?  If not, it
should at least be mentioned in the commit message.

> diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
> index 0a8d9cc9ea..ce43c02314 100644
> --- a/include/qemu/error-report.h
> +++ b/include/qemu/error-report.h
> @@ -34,7 +34,6 @@ void error_vprintf(const char *fmt, va_list ap) 
> GCC_FMT_ATTR(1, 0);
>  void error_printf(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
>  void error_vprintf_unless_qmp(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 
> 0);
>  void error_printf_unless_qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
> -void error_set_progname(const char *argv0);
>  
>  void error_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
>  void warn_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
> @@ -49,6 +48,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 error_init(const char *argv0);
> +
>  /*
>   * Similar to error_report(), except it prints the message just once.
>   * Return true when it prints, false otherwise.
> diff --git a/linux-user/main.c b/linux-user/main.c
> index a0aba9cb1e..f9efe9ff6e 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -27,6 +27,7 @@
>  #include "qemu/path.h"
>  #include "qemu/config-file.h"
>  #include "qemu/cutils.h"
> +#include "qemu/error-report.h"
>  #include "qemu/help_option.h"
>  #include "cpu.h"
>  #include "exec/exec-all.h"
> @@ -600,6 +601,7 @@ int main(int argc, char **argv, char **envp)
>  int ret;
>  int execfd;
>  
> +error_init(argv[0]);
>  module_call_init(MODULE_INIT_TRACE);
>  qemu_init_cpu_list();
>  module_call_init(MODULE_INIT_QOM);

Likewise.

> diff --git a/qemu-img.c b/qemu-img.c
> index ad04f59565..0af9cac244 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -4912,8 +4912,8 @@ int main(int argc, char **argv)
>  signal(SIGPIPE, SIG_IGN);
>  #endif
>  
> +error_init(argv[0]);
>  module_call_init(MODULE_INIT_TRACE);
> -error_set_progname(argv[0]);
>  qemu_init_exec_dir(argv[0]);
>  
>  if (qemu_init_main_loop(_error)) {
> diff --git a/qemu-io.c b/qemu-io.c
> index 2c52ac0ade..8d5d5911cb 100644
> --- a/qemu-io.c
> +++ b/qemu-io.c
> @@ -522,8 +522,8 @@ int main(int argc, char **argv)
>  signal(SIGPIPE, SIG_IGN);
>  #endif
>  
> +error_init(argv[0]);
>  module_call_init(MODULE_INIT_TRACE);
> -error_set_progname(argv[0]);
>  qemu_init_exec_dir(argv[0]);
>  
>  qcrypto_init(_fatal);
> diff --git a/qemu-nbd.c b/qemu-nbd.c
> index 1f7b2a03f5..39849f1692 100644
> --- a/qemu-nbd.c
> +++ b/qemu-nbd.c
> @@ -685,8 +685,8 @@ int main(int argc, char **argv)
>  signal(SIGPIPE, SIG_IGN);
>  #endif
>  
> +error_init(argv[0]);
>  module_call_init(MODULE_INIT_TRACE);
> -error_set_progname(argv[0]);
>  qcrypto_init(_fatal);
>  
>  module_call_init(MODULE_INIT_QOM);
> diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c
> index 

Re: [Qemu-devel] [PATCH v6 2/2] log: Make glib logging go through QEMU

2019-01-28 Thread Stefan Hajnoczi
On Fri, Jan 25, 2019 at 06:22:29PM +0100, Christophe Fergeau wrote:
> 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
> HMP monitor if one is configured.
> This commit also adds a call to qemu_init_logging() to the binaries
> installed by QEMU.
> glib debug messages are enabled through G_MESSAGES_DEBUG similarly to
> 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 
> ---
>  bsd-user/main.c |  2 ++
>  include/qemu/error-report.h |  3 ++-
>  linux-user/main.c   |  2 ++
>  qemu-img.c  |  2 +-
>  qemu-io.c   |  2 +-
>  qemu-nbd.c  |  2 +-
>  scsi/qemu-pr-helper.c   |  1 +
>  util/qemu-error.c   | 48 -
>  vl.c|  2 +-
>  9 files changed, 58 insertions(+), 6 deletions(-)

Reviewed-by: Stefan Hajnoczi 


signature.asc
Description: PGP signature


[Qemu-devel] [PATCH v6 2/2] log: Make glib logging go through QEMU

2019-01-25 Thread Christophe Fergeau
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
HMP monitor if one is configured.
This commit also adds a call to qemu_init_logging() to the binaries
installed by QEMU.
glib debug messages are enabled through G_MESSAGES_DEBUG similarly to
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 
---
 bsd-user/main.c |  2 ++
 include/qemu/error-report.h |  3 ++-
 linux-user/main.c   |  2 ++
 qemu-img.c  |  2 +-
 qemu-io.c   |  2 +-
 qemu-nbd.c  |  2 +-
 scsi/qemu-pr-helper.c   |  1 +
 util/qemu-error.c   | 48 -
 vl.c|  2 +-
 9 files changed, 58 insertions(+), 6 deletions(-)

diff --git a/bsd-user/main.c b/bsd-user/main.c
index 0d3156974c..8fd8ae4127 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -24,6 +24,7 @@
 #include "qapi/error.h"
 #include "qemu.h"
 #include "qemu/config-file.h"
+#include "qemu/error-report.h"
 #include "qemu/path.h"
 #include "qemu/help_option.h"
 #include "cpu.h"
@@ -743,6 +744,7 @@ int main(int argc, char **argv)
 if (argc <= 1)
 usage();
 
+error_init(argv[0]);
 module_call_init(MODULE_INIT_TRACE);
 qemu_init_cpu_list();
 module_call_init(MODULE_INIT_QOM);
diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
index 0a8d9cc9ea..ce43c02314 100644
--- a/include/qemu/error-report.h
+++ b/include/qemu/error-report.h
@@ -34,7 +34,6 @@ void error_vprintf(const char *fmt, va_list ap) 
GCC_FMT_ATTR(1, 0);
 void error_printf(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 void error_vprintf_unless_qmp(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
 void error_printf_unless_qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
-void error_set_progname(const char *argv0);
 
 void error_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
 void warn_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
@@ -49,6 +48,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 error_init(const char *argv0);
+
 /*
  * Similar to error_report(), except it prints the message just once.
  * Return true when it prints, false otherwise.
diff --git a/linux-user/main.c b/linux-user/main.c
index a0aba9cb1e..f9efe9ff6e 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -27,6 +27,7 @@
 #include "qemu/path.h"
 #include "qemu/config-file.h"
 #include "qemu/cutils.h"
+#include "qemu/error-report.h"
 #include "qemu/help_option.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
@@ -600,6 +601,7 @@ int main(int argc, char **argv, char **envp)
 int ret;
 int execfd;
 
+error_init(argv[0]);
 module_call_init(MODULE_INIT_TRACE);
 qemu_init_cpu_list();
 module_call_init(MODULE_INIT_QOM);
diff --git a/qemu-img.c b/qemu-img.c
index ad04f59565..0af9cac244 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -4912,8 +4912,8 @@ int main(int argc, char **argv)
 signal(SIGPIPE, SIG_IGN);
 #endif
 
+error_init(argv[0]);
 module_call_init(MODULE_INIT_TRACE);
-error_set_progname(argv[0]);
 qemu_init_exec_dir(argv[0]);
 
 if (qemu_init_main_loop(_error)) {
diff --git a/qemu-io.c b/qemu-io.c
index 2c52ac0ade..8d5d5911cb 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -522,8 +522,8 @@ int main(int argc, char **argv)
 signal(SIGPIPE, SIG_IGN);
 #endif
 
+error_init(argv[0]);
 module_call_init(MODULE_INIT_TRACE);
-error_set_progname(argv[0]);
 qemu_init_exec_dir(argv[0]);
 
 qcrypto_init(_fatal);
diff --git a/qemu-nbd.c b/qemu-nbd.c
index 1f7b2a03f5..39849f1692 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -685,8 +685,8 @@ int main(int argc, char **argv)
 signal(SIGPIPE, SIG_IGN);
 #endif
 
+error_init(argv[0]);
 module_call_init(MODULE_INIT_TRACE);
-error_set_progname(argv[0]);
 qcrypto_init(_fatal);
 
 module_call_init(MODULE_INIT_QOM);
diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c
index e7af637232..2541fbbd1b 100644
--- a/scsi/qemu-pr-helper.c
+++ b/scsi/qemu-pr-helper.c
@@ -895,6 +895,7 @@ int main(int argc, char **argv)
 
 signal(SIGPIPE, SIG_IGN);
 
+error_init(argv[0]);
 module_call_init(MODULE_INIT_TRACE);
 module_call_init(MODULE_INIT_QOM);
 qemu_add_opts(_trace_opts);
diff --git a/util/qemu-error.c b/util/qemu-error.c
index fcbe8a1f74..2684870683 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -142,7 +142,7 @@ static const char *progname;
 /*