[virt-tools-list] [virt-viewer] log: Handle G_MESSAGES_DEBUG with older glibs

Christophe Fergeau cfergeau at redhat.com
Thu Jun 12 12:37:08 UTC 2014


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.
---
 src/virt-viewer-app.c  |  3 +--
 src/virt-viewer-util.c | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index 7dbb7fc..ad571c8 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -181,7 +181,6 @@ 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) {
@@ -193,7 +192,7 @@ virt_viewer_app_set_debug(gboolean debug)
             g_free(newdoms);
         }
     }
-#endif
+
     doDebug = debug;
 }
 
diff --git a/src/virt-viewer-util.c b/src/virt-viewer-util.c
index 6fdaa07..6a20291 100644
--- a/src/virt-viewer-util.c
+++ b/src/virt-viewer-util.c
@@ -283,9 +283,19 @@ 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)
+#if !GLIB_CHECK_VERSION(2, 31, 0)
+    /* Older glibs were showing G_LOG_LEVEL_DEBUG messages by default */
+    if ((log_level == G_LOG_LEVEL_INFO)
+        || (log_level == G_LOG_LEVEL_DEBUG)) {
+        const char *domains = g_getenv ("G_MESSAGES_DEBUG");
+
+	if (domains == NULL)
+	    return;
+	if ((strcmp(domains, "all") != 0) &&
+	     (strstr(domains, G_LOG_DOMAIN) == NULL))
             return;
+    }
+#endif
 
     g_log_default_handler(log_domain, log_level, message, unused_data);
 }
-- 
1.9.3




More information about the virt-tools-list mailing list