[gnome-disk-utility] only spew debug if GDU_DEBUG is set to 1



commit e98da9ff4af7ac297a0154e7ec29048ea6359bb9
Author: David Zeuthen <davidz redhat com>
Date:   Wed Apr 15 09:40:58 2009 -0400

    only spew debug if GDU_DEBUG is set to 1
---
 src/gdu/gdu-device.c |    2 +-
 src/gdu/gdu-pool.c   |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletions(-)

diff --git a/src/gdu/gdu-device.c b/src/gdu/gdu-device.c
index 78d774b..5a8fcd6 100644
--- a/src/gdu/gdu-device.c
+++ b/src/gdu/gdu-device.c
@@ -658,7 +658,7 @@ _gdu_device_new_from_object_path (GduPool *pool, const char *object_path)
         if (!update_info (device))
                 goto error;
 
-        g_print ("%s: %s\n", __FUNCTION__, device->priv->props->device_file);
+        g_debug ("_gdu_device_new_from_object_path: %s", device->priv->props->device_file);
 
         return device;
 error:
diff --git a/src/gdu/gdu-pool.c b/src/gdu/gdu-pool.c
index 8435822..0a337ed 100644
--- a/src/gdu/gdu-pool.c
+++ b/src/gdu/gdu-pool.c
@@ -249,8 +249,40 @@ gdu_pool_class_init (GduPoolClass *klass)
 }
 
 static void
+gdu_log_func (const gchar   *log_domain,
+              GLogLevelFlags log_level,
+              const gchar   *message,
+              gpointer       user_data)
+{
+        gboolean show_debug;
+        const gchar *gdu_debug_var;
+
+        gdu_debug_var = g_getenv ("GDU_DEBUG");
+        show_debug = (g_strcmp0 (gdu_debug_var, "1") == 0);
+
+        if (G_LIKELY (!show_debug))
+                goto out;
+
+        g_print ("%s: %s\n",
+                 G_LOG_DOMAIN,
+                 message);
+ out:
+        ;
+}
+
+static void
 gdu_pool_init (GduPool *pool)
 {
+        static gboolean log_handler_initialized = FALSE;
+
+        if (!log_handler_initialized) {
+                g_log_set_handler (G_LOG_DOMAIN,
+                                   G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG,
+                                   gdu_log_func,
+                                   NULL);
+                log_handler_initialized = TRUE;
+        }
+
         pool->priv = G_TYPE_INSTANCE_GET_PRIVATE (pool, GDU_TYPE_POOL, GduPoolPrivate);
 
         pool->priv->object_path_to_device = g_hash_table_new_full (g_str_hash,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]