Commit 2bd835fb introduced a custom log handler to ensure we never show debug messages by default regardless of glib version (older glib were showing them by default). However this custom log handler does not take into account G_MESSAGES_DEBUG. This commit adds support for that and makes the handling of --debug identical between older and newer glibs. --- Changes since v1: - on older glibs, only do the getenv dance once instead of once per log-message src/virt-viewer-app.c | 17 ++++++++++------- src/virt-viewer-util.c | 8 +++++--- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c index 24ca5c1..a523090 100644 --- a/src/virt-viewer-app.c +++ b/src/virt-viewer-app.c @@ -183,19 +183,22 @@ static guint signals[SIGNAL_LAST]; void virt_viewer_app_set_debug(gboolean debug) { -#if GLIB_CHECK_VERSION(2, 31, 0) - if (debug) { - const gchar *doms = g_getenv("G_MESSAGES_DEBUG"); - if (!doms) { + const gchar *doms = g_getenv("G_MESSAGES_DEBUG"); + if (!doms) { + if (debug) g_setenv("G_MESSAGES_DEBUG", G_LOG_DOMAIN, 1); - } else if (!g_str_equal(doms, "all") && - !strstr(doms, G_LOG_DOMAIN)) { + } else if (!g_str_equal(doms, "all") && + !strstr(doms, G_LOG_DOMAIN)) { + if (debug) { gchar *newdoms = g_strdup_printf("%s %s", doms, G_LOG_DOMAIN); g_setenv("G_MESSAGES_DEBUG", newdoms, 1); g_free(newdoms); } + } else { + /* G_MESSAGES_DEBUG=all or G_MESSAGES_DEBUG contains G_LOG_DOMAIN */ + debug = TRUE; } -#endif + doDebug = debug; } diff --git a/src/virt-viewer-util.c b/src/virt-viewer-util.c index 6fdaa07..f4bd20a 100644 --- a/src/virt-viewer-util.c +++ b/src/virt-viewer-util.c @@ -283,9 +283,11 @@ static void log_handler(const gchar *log_domain, const gchar *message, gpointer unused_data) { - if (glib_check_version(2, 32, 0) != NULL) - if (log_level >= G_LOG_LEVEL_DEBUG && !doDebug) - return; +#if !GLIB_CHECK_VERSION(2, 31, 0) + /* Older glibs were showing G_LOG_LEVEL_{INFO,DEBUG} messages by default */ + if (log_level >= G_LOG_LEVEL_INFO && !doDebug) + return; +#endif g_log_default_handler(log_domain, log_level, message, unused_data); } -- 1.9.3 _______________________________________________ virt-tools-list mailing list virt-tools-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/virt-tools-list