Skip to contentSkip to conversation

log: Make glib logging go through QEMU

PATCH Superseded Christophe Fergeau 3 participants 3 messages Dec 13, 2018

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 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.
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.

---
Changes since v2:
- report G_LOG_LEVEL_CRITICAL using error_report() instead of warn_report()
- print G_LOG_LEVEL_DEBUG messages when G_MESSAGES_DEBUG is set
- prepend glib log domain to messages

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           | 47 +++++++++++++++++++++++++++++++++++++
 vl.c                        |  1 +
 9 files changed, 56 insertions(+)
bsd-user/main.c +1 -0
index 0d3156974c..96787b27ef 100644
@@ -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
index 0a8d9cc9ea..2852e9df2a 100644
@@ -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
index 923cbb753a..de9ff462e9 100644
@@ -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
index ad04f59565..9214392565 100644
@@ -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
index 6df7731af4..ad38d12e68 100644
@@ -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
index ca7109652e..2cac038230 100644
@@ -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
index e7af637232..523f8b237c 100644
@@ -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 +47 -0

50 lines not on this page · raw message

vl.c +1 -0
index a5ae5f23d2..d986fd93ab 100644
@@ -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
Reviewed-by on v3 1/1
#1 lore raw
Quoted 10 lines · 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 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.

Quoted 6 lines

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.

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 :|
#2 lore raw
In reply to Christophe Fergeau
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH v3] log: Make glib logging go through QEMU

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
4da29cf log: Make glib logging go through QEMU

=== OUTPUT BEGIN ===
Checking PATCH 1/1: log: Make glib logging go through QEMU...
ERROR: space prohibited between function name and open parenthesis '(' #133: FILE: util/qemu-error.c:364:
+ if (strcmp (qemu_glog_domains, "all") != 0 &&

ERROR: space prohibited between function name and open parenthesis '(' #134: FILE: util/qemu-error.c:365:
+ (log_domain == NULL || !strstr (qemu_glog_domains, log_domain))) {

total: 2 errors, 0 warnings, 107 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]