[grilo] core: ensure the default log domain is always set



commit a5f19ef95a7a5e41de5ad3b5b61ab409100d6052
Author: Guillaume Emont <guijemont igalia com>
Date:   Wed May 11 19:45:39 2011 +0200

    core: ensure the default log domain is always set
    
    This also avoid the risky #define-ing of GRL_LOG_DOMAIN_DEFAULT in grl-log.c:
    in this file, GRL_LOG_DOMAIN_DEFAULT now always refers to the actual variable,
    to avoid confusions.

 src/grl-log.c |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/src/grl-log.c b/src/grl-log.c
index 5895b09..3033385 100644
--- a/src/grl-log.c
+++ b/src/grl-log.c
@@ -48,9 +48,11 @@ static GrlLogLevel grl_default_log_level = GRL_LOG_LEVEL_WARNING;
 static GSList *log_domains = NULL;  /* the list of GrlLogDomain's */
 
 /* Catch all log domain */
+/* For clarity, it should not be re-#define'd in this file, code that wants to
+ * log things with log_log_domain should do it explicitly using GRL_LOG(),
+ * instead of using GRL_{DEBUG,INFO,MESSAGE,WARNING,ERROR}() */
 GRL_LOG_DOMAIN(GRL_LOG_DOMAIN_DEFAULT);
 
-#define GRL_LOG_DOMAIN_DEFAULT  log_log_domain
 GRL_LOG_DOMAIN(log_log_domain);
 
 static GrlLogDomain *
@@ -73,7 +75,7 @@ _grl_log_domain_new_internal (const gchar *name)
 {
   GrlLogDomain *domain;
 
-  if (*name == '\0')
+  if (*name == '\0' && GRL_LOG_DOMAIN_DEFAULT != NULL)
     return GRL_LOG_DOMAIN_DEFAULT;
 
   domain = g_slice_new (GrlLogDomain);
@@ -82,6 +84,10 @@ _grl_log_domain_new_internal (const gchar *name)
 
   log_domains = g_slist_prepend (log_domains, domain);
 
+  if (*name == '\0' && GRL_LOG_DOMAIN_DEFAULT == NULL)
+    /* Ensure GRL_LOG_DOMAIN_DEFAULT is set. */
+    GRL_LOG_DOMAIN_DEFAULT = domain;
+
   return domain;
 }
 
@@ -246,11 +252,13 @@ configure_log_domains (const gchar *domains)
 
       domain->log_level = level;
 
-      GRL_DEBUG ("domain: '%s', level: '%s'", domain_spec, level_spec);
+      GRL_LOG (log_log_domain, GRL_LOG_LEVEL_DEBUG,
+               "domain: '%s', level: '%s'", domain_spec, level_spec);
 
       g_strfreev (pair_info);
     } else {
-      GRL_WARNING ("Invalid log spec: '%s'", *pair);
+      GRL_LOG (log_log_domain, GRL_LOG_LEVEL_WARNING,
+               "Invalid log spec: '%s'", *pair);
     }
     pair++;
   }
@@ -329,7 +337,8 @@ _grl_log_init_core_domains (void)
    * verbosity */
   log_env = g_getenv ("GRL_DEBUG");
   if (log_env) {
-    GRL_DEBUG ("Using log configuration from GRL_DEBUG: %s", log_env);
+    GRL_LOG (log_log_domain, GRL_LOG_LEVEL_DEBUG,
+             "Using log configuration from GRL_DEBUG: %s", log_env);
     configure_log_domains (log_env);
     grl_log_env = g_strsplit (log_env, ",", 0);
   }



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