[core 2/6] log: revamp the log system



From: Damien Lespiau <damien lespiau intel com>

Current log system suffers from a few drawbacks:

  * It uses Glib's default handler for all the domains, this handler should
    not be overriden by a library (imagine what can happen if every
    library depends on being able to override the default log handler),

  * You can't use the common practice to break on g_log() to trace where
    warnings come from because the decision of printing the message is
    taken in the handler itself,

  * Other gnome libraries tend to define a single glib log domain for
    the whole library.

So, instead, use a GStreamer-like logging system, with "log domains" you
have to declare and initialize.

This patch tries to keep the original author's intent by keeping:

  * the glib's debug levels and using them in the final g_logv(),

  * the same decoding of the string given to grl_log_init().

It also modifies a bit when the GRL_LOG env variable is sampled. Instead
of requiring the use to explictely call grl_log_init() to check the
GRL_LOG behing the scene, grilo now gets this variable at startup and
overrides the default verbosity level of log domains when they are
created.

grl_log_init() can still be used to set the verbosity, it has to be
called after the log domain has been initialized which, for plugins,
means after having loaded the plugin.

https://bugzilla.gnome.org/show_bug.cgi?id=627864
---
 src/Makefile.am                   |    5 +-
 src/data/grl-config.c             |    7 +-
 src/data/grl-data.c               |   11 +-
 src/data/grl-media.c              |   14 +-
 src/grilo.c                       |    9 +-
 src/{grl-log.h => grl-log-priv.h} |   28 ++-
 src/grl-log.c                     |  341 ++++++++++++++++++++++++++++---------
 src/grl-log.h                     |  246 ++++++++++++++++++++++++++-
 src/grl-media-plugin.c            |    5 +-
 src/grl-media-source.c            |  159 +++++++++---------
 src/grl-metadata-source.c         |   57 +++---
 src/grl-multiple.c                |   55 +++---
 src/grl-plugin-registry.c         |   53 +++---
 src/tests/registry.c              |   14 +-
 tools/grilo-test-ui/main.c        |   59 ++++---
 15 files changed, 757 insertions(+), 306 deletions(-)
 copy src/{grl-log.h => grl-log-priv.h} (55%)

diff --git a/src/Makefile.am b/src/Makefile.am
index 526dba4..0a1b563 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -15,7 +15,8 @@ lib GRL_NAME@_la_CFLAGS =	\
 	$(DEPS_CFLAGS)		\
 	-I$(srcdir)		\
 	-I$(srcdir)/data	\
-	-DGRILO_COMPILATION
+	-DGRILO_COMPILATION	\
+	-DG_LOG_DOMAIN=\"Grilo\"
 
 lib GRL_NAME@_la_LIBADD =	\
 	$(DEPS_LIBS)
@@ -27,7 +28,7 @@ lib GRL_NAME@_la_SOURCES =					\
 	grl-metadata-source.c grl-metadata-source-priv.h	\
 	grl-media-source.c grl-util.c				\
 	grl-multiple.c						\
-	grl-log.c						\
+	grl-log.c grl-log-priv.h				\
 	grl-sync.c						\
 	grilo.c
 
diff --git a/src/data/grl-config.c b/src/data/grl-config.c
index 382b921..bf911fe 100644
--- a/src/data/grl-config.c
+++ b/src/data/grl-config.c
@@ -30,9 +30,10 @@
  */
 
 #include "grl-config.h"
+#include "grl-log.h"
 
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "grl-config"
+#define GRL_LOG_DOMAIN_DEFAULT  config_log_domain
+GRL_LOG_DOMAIN(config_log_domain);
 
 #define GRL_CONFIG_GET_PRIVATE(o)                                         \
   (G_TYPE_INSTANCE_GET_PRIVATE ((o), GRL_TYPE_CONFIG, GrlConfigPrivate))
@@ -85,7 +86,7 @@ grl_config_dispose (GObject *object)
 static void
 grl_config_finalize (GObject *object)
 {
-  g_debug ("grl_config_finalize");
+  GRL_DEBUG ("grl_config_finalize");
   g_signal_handlers_destroy (object);
   G_OBJECT_CLASS (grl_config_parent_class)->finalize (object);
 }
diff --git a/src/data/grl-data.c b/src/data/grl-data.c
index 8ee9bea..194be75 100644
--- a/src/data/grl-data.c
+++ b/src/data/grl-data.c
@@ -33,6 +33,7 @@
  */
 
 #include "grl-data.h"
+#include "grl-log.h"
 
 enum {
   PROP_0,
@@ -208,15 +209,15 @@ grl_data_set (GrlData *data, GrlKeyID key, const GValue *value)
         g_value_init (copy, G_VALUE_TYPE (value));
         g_value_copy (value, copy);
       } else {
-        g_warning ("value has type %s, but expected %s",
-                   g_type_name (G_VALUE_TYPE (value)),
-                   g_type_name (GRL_METADATA_KEY_GET_TYPE (key)));
+        GRL_WARNING ("value has type %s, but expected %s",
+                     g_type_name (G_VALUE_TYPE (value)),
+                     g_type_name (GRL_METADATA_KEY_GET_TYPE (key)));
       }
     }
 
     if (copy && g_param_value_validate (key, copy)) {
-      g_warning ("'%s' value invalid, adjusting",
-                 GRL_METADATA_KEY_GET_NAME (key));
+      GRL_WARNING ("'%s' value invalid, adjusting",
+                   GRL_METADATA_KEY_GET_NAME (key));
     }
     g_hash_table_insert (data->priv->data, key, copy);
   }
diff --git a/src/data/grl-media.c b/src/data/grl-media.c
index cc5f931..3a255b1 100644
--- a/src/data/grl-media.c
+++ b/src/data/grl-media.c
@@ -35,8 +35,8 @@
 #include <grilo.h>
 #include <stdlib.h>
 
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "grl-media"
+#define GRL_LOG_DOMAIN_DEFAULT  media_log_domain
+GRL_LOG_DOMAIN(media_log_domain);
 
 #define RATING_MAX  5.00
 #define SERIAL_STRING_ALLOC 100
@@ -69,9 +69,9 @@ grl_media_dispose (GObject *object)
 static void
 grl_media_finalize (GObject *object)
 {
-  g_debug ("grl_media_finalize (%s)",
-	   grl_data_get_string (GRL_DATA (object),
-                                GRL_METADATA_KEY_TITLE));
+  GRL_DEBUG ("grl_media_finalize (%s)",
+                 grl_data_get_string (GRL_DATA (object),
+                                      GRL_METADATA_KEY_TITLE));
   g_signal_handlers_destroy (object);
   G_OBJECT_CLASS (grl_media_parent_class)->finalize (object);
 }
@@ -279,7 +279,7 @@ grl_media_unserialize (const gchar *serial)
                  0,
                  NULL);
   if (!g_regex_match (uri_regex, serial, 0, &match_info)) {
-    g_warning ("Wrong serial %s", serial);
+    GRL_WARNING ("Wrong serial %s", serial);
     g_regex_unref (uri_regex);
     return NULL;
   }
@@ -301,7 +301,7 @@ grl_media_unserialize (const gchar *serial)
   if (type_media) {
     media = GRL_MEDIA (g_object_new (type_media, NULL));
   } else {
-    g_warning ("There is no type %s", type_name);
+    GRL_WARNING ("There is no type %s", type_name);
     g_free (type_name);
     g_match_info_free (match_info);
     return NULL;
diff --git a/src/grilo.c b/src/grilo.c
index 2681e34..72964bb 100644
--- a/src/grilo.c
+++ b/src/grilo.c
@@ -22,6 +22,7 @@
 
 #include "grilo.h"
 #include "grl-metadata-key-priv.h"
+#include "grl-log-priv.h"
 #include "config.h"
 
 #define GRL_PLUGIN_PATH_DEFAULT GRL_PLUGINS_DIR
@@ -47,7 +48,7 @@ grl_init (gint *argc,
   gchar **plugin_dirs_split;
 
   if (grl_initialized) {
-    g_debug ("already initialized grl");
+    GRL_DEBUG ("already initialized grl");
     return;
   }
 
@@ -63,11 +64,11 @@ grl_init (gint *argc,
 
   /* Initialize GModule */
   if (!g_module_supported ()) {
-    g_error ("GModule not supported in this system");
+    GRL_ERROR ("GModule not supported in this system");
   }
 
-  /* Setup default log verbosity */
-  grl_log_init ("*:warning");
+  /* Setup core log domains */
+  _grl_log_init_core_domains ();
 
   /* Register default metadata keys */
   registry = grl_plugin_registry_get_default ();
diff --git a/src/grl-log.h b/src/grl-log-priv.h
similarity index 55%
copy from src/grl-log.h
copy to src/grl-log-priv.h
index 486802a..abe2389 100644
--- a/src/grl-log.h
+++ b/src/grl-log-priv.h
@@ -1,7 +1,7 @@
 /*
- * Copyright (C) 2010 Igalia S.L.
+ * Copyright (C) 2010 Intel Corporation
  *
- * Contact: Iago Toral Quiroga <itoral igalia com>
+ * Contact: Damien Lespiau <damien lespiau intel com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
@@ -20,19 +20,27 @@
  *
  */
 
-#if !defined (_GRILO_H_INSIDE_) && !defined (GRILO_COMPILATION)
-#error "Only <grilo.h> can be included directly."
-#endif
-
-#ifndef _GRL_LOG_H_
-#define _GRL_LOG_H_
+#ifndef _GRL_LOG_PRIV_H_
+#define _GRL_LOG_PRIV_H_
 
 #include <glib.h>
 
+#include "grl-log.h"
+
 G_BEGIN_DECLS
 
-void grl_log_init (const gchar *domains);
+GRL_LOG_DOMAIN_EXTERN(log_log_domain);
+GRL_LOG_DOMAIN_EXTERN(config_log_domain);
+GRL_LOG_DOMAIN_EXTERN(media_log_domain);
+GRL_LOG_DOMAIN_EXTERN(media_plugin_log_domain);
+GRL_LOG_DOMAIN_EXTERN(media_source_log_domain);
+GRL_LOG_DOMAIN_EXTERN(metadata_source_log_domain);
+GRL_LOG_DOMAIN_EXTERN(multiple_log_domain);
+GRL_LOG_DOMAIN_EXTERN(plugin_registry_log_domain);
+
+void _grl_log_init_core_domains (void);
+void _grl_log_free_core_domains (void);
 
 G_END_DECLS
 
-#endif /* _GRL_LOG_H_ */
+#endif /* _GRL_LOG_PRIV_H_ */
diff --git a/src/grl-log.c b/src/grl-log.c
index 55a75c2..4c9748b 100644
--- a/src/grl-log.c
+++ b/src/grl-log.c
@@ -21,71 +21,169 @@
  */
 
 #include "grl-log.h"
+#include "grl-log-priv.h"
 
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "grl-log"
+#include <stdarg.h>
+#include <string.h>
 
-#define GRL_DEFAULT_LOG_SPEC (G_LOG_LEVEL_WARNING |     \
-                              G_LOG_LEVEL_CRITICAL |    \
-                              G_LOG_LEVEL_ERROR)
+struct _GrlLogDomain {
+  /*< private >*/
+  GrlLogLevel log_level;
+  char *name;
+};
 
-static void
-grl_log_handler (const gchar *domain,
-                 GLogLevelFlags level,
-                 const gchar *message,
-                 gpointer user_data)
+
+static gchar **grl_log_env;          /* 'domain:level' array from GRL_LOG */
+
+static GrlLogLevel grl_default_log_level = GRL_LOG_LEVEL_WARNING;
+static GSList *log_domains = NULL;  /* the list of GrlLogDomain's */
+
+/* Catch all log domain */
+GRL_LOG_DOMAIN(GRL_LOG_DOMAIN_DEFAULT);
+
+#define GRL_LOG_DOMAIN_DEFAULT  log_log_domain
+GRL_LOG_DOMAIN(log_log_domain);
+
+static GrlLogDomain *
+grl_log_domain_find_by_name (const gchar *name)
 {
-  GLogLevelFlags levels = GPOINTER_TO_INT (user_data);
-  if (level & levels)
-    g_log_default_handler (domain, level, message, NULL);
+  GSList *list;
+
+  for (list = log_domains; list; list = g_slist_next (list)) {
+    GrlLogDomain *log_domain = list->data;
+
+    if (g_strcmp0 (log_domain->name, name) == 0)
+      return log_domain;
+  }
+
+  return NULL;
 }
 
-static const gchar *
-get_domain_from_spec (const gchar *domain_spec)
+static GrlLogDomain *
+_grl_log_domain_new_internal (const gchar *name)
 {
-  if (!g_ascii_strcasecmp ("default", domain_spec) ||
-      !g_ascii_strcasecmp ("", domain_spec)) {
-    return NULL; /* Default domain */
-  } else {
-    return domain_spec;
-  }
+  GrlLogDomain *domain;
+
+  if (*name == '\0')
+    return GRL_LOG_DOMAIN_DEFAULT;
+
+  domain = g_slice_new (GrlLogDomain);
+  domain->log_level = grl_default_log_level;
+  domain->name = g_strdup (name);
+
+  log_domains = g_slist_prepend (log_domains, domain);
+
+  return domain;
 }
 
-static GLogLevelFlags
-get_log_levels_from_spec (const gchar *level_spec)
+GrlLogDomain *
+grl_log_domain_new (const gchar *name)
 {
-  GLogLevelFlags levels = 0;
+  GrlLogDomain *domain;
+  gchar **pair;
 
-  if (!g_ascii_strcasecmp (level_spec, "-")) {
-    return levels;
-  }
-  levels |= G_LOG_LEVEL_ERROR;
-  if (!g_ascii_strcasecmp (level_spec , "error")) {
-    return levels;
-  }
-  levels |= G_LOG_LEVEL_CRITICAL;
-  if (!g_ascii_strcasecmp (level_spec , "critical")) {
-    return levels;
-  }
-  levels |= G_LOG_LEVEL_WARNING;
-  if (!g_ascii_strcasecmp (level_spec , "warning")) {
-    return levels;
+  g_return_val_if_fail (name, NULL);
+
+  domain = _grl_log_domain_new_internal (name);
+
+  /* If the GRL_LOG env variable contains @name, let's override that domain
+   * verbosity */
+  if (grl_log_env == NULL)
+    return domain;
+
+  pair = grl_log_env;
+
+  while (*pair) {
+    gchar **pair_info;
+    gchar *domain_spec;
+
+    pair_info = g_strsplit (*pair, ":", 2);
+    domain_spec = pair_info[0];
+
+    if (g_strcmp0 (domain_spec, name) == 0)
+      grl_log_init (*pair);
+
+    g_strfreev (pair_info);
+    pair++;
   }
-  levels |= G_LOG_LEVEL_MESSAGE;
-  if (!g_ascii_strcasecmp (level_spec , "message")) {
-    return levels;
+
+  return domain;
+}
+
+static void
+_grl_log_domain_free_internal (GrlLogDomain *domain)
+{
+  log_domains = g_slist_remove (log_domains, domain);
+  g_free (domain->name);
+  g_slice_free (GrlLogDomain, domain);
+}
+
+void
+grl_log_domain_free (GrlLogDomain *domain)
+{
+  g_return_if_fail (domain);
+
+  /* domain can actually be GRL_LOG_DOMAIN_DEFAULT if the domain name given
+   * in _new() was "", freeing the default domain is not possible from the
+   * public API */
+  if (domain == GRL_LOG_DOMAIN_DEFAULT)
+    return;
+
+  _grl_log_domain_free_internal (domain);
+}
+
+static void
+grl_log_domain_set_level_all (GrlLogLevel level)
+{
+  GSList *list;
+
+  /* Set the default log level to be level, so newly created domains will
+   * have the correct level */
+  grl_default_log_level = level;
+
+  for (list = log_domains; list; list = g_slist_next (list)) {
+    GrlLogDomain *log_domain = list->data;
+
+    log_domain->log_level = level;
   }
-  levels |= G_LOG_LEVEL_INFO;
-  if (!g_ascii_strcasecmp (level_spec , "info")) {
-    return levels;
+}
+
+static GrlLogDomain *
+get_domain_from_spec (const gchar *domain_spec)
+{
+  GrlLogDomain *domain;
+
+  domain = grl_log_domain_find_by_name (domain_spec);
+
+  return domain;
+}
+
+static gchar *name2level[GRL_LOG_LEVEL_LAST] = {
+  "none", "error", "warning", "message", "info", "debug"
+};
+
+static GrlLogLevel
+get_log_level_from_spec (const gchar *level_spec)
+{
+  guint i;
+
+  /* "-" or "none" (from name2level) can be used to disable all logging */
+  if (strcmp (level_spec, "-") == 0) {
+    return GRL_LOG_LEVEL_NONE;
   }
-  levels |= G_LOG_LEVEL_DEBUG;
-  if (!g_ascii_strcasecmp (level_spec , "debug") ||
-      !g_ascii_strcasecmp (level_spec , "*")) {
-    return levels;
+
+  /* '*' means everything */
+  if (strcmp (level_spec, "*") == 0) {
+    return GRL_LOG_LEVEL_LAST - 1;
   }
 
-  return levels;
+  for (i = 0; i < GRL_LOG_LEVEL_LAST; i++)
+    if (strcmp (level_spec, name2level[i]) == 0)
+      return i;
+
+  /* If the spec does not match one of our levels, just return the current
+   * default log level */
+  return grl_default_log_level;
 }
 
 static void
@@ -96,23 +194,8 @@ setup_log_domains (const gchar *domains)
   gchar **pair_info ;
   gchar *domain_spec;
   gchar *level_spec;
-  const gchar *domain;
-  GLogLevelFlags levels;
-  const gchar *env_log;
-
-  /* Default logging policy */
-  g_log_set_default_handler (grl_log_handler,
-			     GINT_TO_POINTER (GRL_DEFAULT_LOG_SPEC));
-
-  /* Now check user specs for specific domains, the user may change also the
-     default set above by using "*" as domain name */
-
-  /* First check environment for log configuration */
-  env_log = g_getenv ("GRL_LOG");
-  if (env_log) {
-    domains = env_log;
-    g_debug ("Using log configuration from $GRL_LOG");
-  }
+  GrlLogDomain *domain;
+  GrlLogLevel level;
 
   pair = pairs = g_strsplit (domains, ",", 0);
 
@@ -121,26 +204,130 @@ setup_log_domains (const gchar *domains)
     if (pair_info[0] && pair_info[1]) {
       domain_spec = pair_info[0];
       level_spec = pair_info[1];
-      g_debug ("domain: '%s', level: '%s'", domain_spec, level_spec);
-      levels = get_log_levels_from_spec (level_spec);
+
+      level = get_log_level_from_spec (level_spec);
       domain = get_domain_from_spec (domain_spec);
-      if (!g_ascii_strcasecmp (domain, "*")) {
-	g_log_set_default_handler (grl_log_handler, GINT_TO_POINTER (levels));
-      } else {
-	g_log_set_handler (domain,
-			   G_LOG_LEVEL_MASK |
-                           G_LOG_FLAG_RECURSION |
-                           G_LOG_FLAG_FATAL,
-			   grl_log_handler, GINT_TO_POINTER (levels));
+
+      if (strcmp (domain_spec, "*") == 0)
+        grl_log_domain_set_level_all (level);
+
+      if (domain == NULL) {
+       g_strfreev (pair_info);
+       pair++;
+       continue;
       }
+
+      domain->log_level = level;
+
+      GRL_DEBUG ("domain: '%s', level: '%s'", domain_spec, level_spec);
+
+      g_strfreev (pair_info);
     } else {
-      g_warning ("Invalid log spec: '%s'", *pair);
+      GRL_WARNING ("Invalid log spec: '%s'", *pair);
     }
     pair++;
   }
   g_strfreev (pairs);
 }
 
+static void
+grl_log_valist (GrlLogDomain *domain,
+                GrlLogLevel   level,
+                const gchar  *strloc,
+                const gchar  *format,
+                va_list       args)
+{
+  gchar *message;
+  GLogLevelFlags level2flag[GRL_LOG_LEVEL_LAST] = {
+    0, G_LOG_LEVEL_CRITICAL, G_LOG_LEVEL_WARNING, G_LOG_LEVEL_MESSAGE,
+    G_LOG_LEVEL_INFO, G_LOG_LEVEL_DEBUG
+  };
+
+  g_return_if_fail (domain);
+  g_return_if_fail (level > 0 && level < GRL_LOG_LEVEL_LAST);
+  g_return_if_fail (strloc);
+  g_return_if_fail (format);
+
+  message = g_strdup_vprintf (format, args);
+
+  if (level <= domain->log_level)
+    g_log (G_LOG_DOMAIN, level2flag[level],
+           "[%s] %s: %s", domain->name, strloc, message);
+
+  g_free (message);
+}
+
+void
+grl_log (GrlLogDomain *domain,
+         GrlLogLevel   level,
+         const gchar  *strloc,
+         const gchar  *format,
+         ...)
+{
+  va_list var_args;
+
+  va_start (var_args, format);
+  grl_log_valist (domain, level, strloc, format, var_args);
+  va_end (var_args);
+}
+
+#define DOMAIN_INIT(domain, name) G_STMT_START {  \
+    domain = _grl_log_domain_new_internal (name); \
+} G_STMT_END
+
+void
+_grl_log_init_core_domains (void)
+{
+  const gchar *log_env;
+
+  DOMAIN_INIT (GRL_LOG_DOMAIN_DEFAULT, "");
+  DOMAIN_INIT (log_log_domain, "log");
+  DOMAIN_INIT (config_log_domain, "config");
+  DOMAIN_INIT (media_log_domain, "media");
+  DOMAIN_INIT (media_plugin_log_domain, "media-plugin");
+  DOMAIN_INIT (media_source_log_domain, "media-source");
+  DOMAIN_INIT (metadata_source_log_domain, "metadata-source");
+  DOMAIN_INIT (multiple_log_domain, "multiple");
+  DOMAIN_INIT (plugin_registry_log_domain, "plugin-registry");
+
+  /* Retrieve the GRL_LOG environment variable, initialize core domains from
+   * it if applicable and keep it for grl_log_domain_new(). Plugins are using
+   * grl_log_domain_new() in their init() functions to initialize their log
+   * domains. At that time, we'll look at the saved GRL_LOG to overrive the
+   * verbosity */
+  log_env = g_getenv ("GRL_LOG");
+  if (log_env) {
+    GRL_DEBUG ("Using log configuration from GRL_LOG: %s", log_env);
+    setup_log_domains (log_env);
+    grl_log_env = g_strsplit (log_env, ",", 0);
+  }
+
+}
+
+#undef DOMAIN_INIT
+
+#define DOMAIN_FREE(domain) G_STMT_START {  \
+    _grl_log_domain_free_internal (domain);   \
+} G_STMT_END
+
+void
+_grl_log_free_core_domains (void)
+{
+  DOMAIN_FREE (GRL_LOG_DOMAIN_DEFAULT);
+  DOMAIN_FREE (log_log_domain);
+  DOMAIN_FREE (config_log_domain);
+  DOMAIN_FREE (media_log_domain);
+  DOMAIN_FREE (media_plugin_log_domain);
+  DOMAIN_FREE (media_source_log_domain);
+  DOMAIN_FREE (metadata_source_log_domain);
+  DOMAIN_FREE (multiple_log_domain);
+  DOMAIN_FREE (plugin_registry_log_domain);
+
+  g_strfreev (grl_log_env);
+}
+
+#undef DOMAIN_FREE
+
 void
 grl_log_init (const gchar *domains)
 {
diff --git a/src/grl-log.h b/src/grl-log.h
index 486802a..921f124 100644
--- a/src/grl-log.h
+++ b/src/grl-log.h
@@ -1,5 +1,9 @@
 /*
- * Copyright (C) 2010 Igalia S.L.
+ * Copyright (C) 1999,2000 Erik Walthinsen <omega cse ogi edu>
+ *                    2000 Wim Taymans <wtay chello be>
+ *                    2003 Benjamin Otte <in7y118 public uni-hamburg de>
+ *                    2010 Igalia S.L.
+ *                    2010 Intel Corporation
  *
  * Contact: Iago Toral Quiroga <itoral igalia com>
  *
@@ -18,6 +22,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA
  *
+ * Part of this code has been adapted from GStreamer gst/gstinfo.h
  */
 
 #if !defined (_GRILO_H_INSIDE_) && !defined (GRILO_COMPILATION)
@@ -31,7 +36,244 @@
 
 G_BEGIN_DECLS
 
-void grl_log_init (const gchar *domains);
+typedef enum {
+  GRL_LOG_LEVEL_NONE,
+  GRL_LOG_LEVEL_ERROR,
+  GRL_LOG_LEVEL_WARNING,
+  GRL_LOG_LEVEL_MESSAGE,
+  GRL_LOG_LEVEL_INFO,
+  GRL_LOG_LEVEL_DEBUG,
+
+  GRL_LOG_LEVEL_LAST
+} GrlLogLevel;
+
+/* Opaque type */
+typedef struct _GrlLogDomain GrlLogDomain;
+
+extern GrlLogDomain *GRL_LOG_DOMAIN_DEFAULT;
+
+/*
+ * GRL_LOG_DOMAIN:
+ * @domain: the log domain
+ *
+ * Defines a GrlLogDomain variable.
+ * This macro expands to nothing if debugging is disabled.
+ */
+
+#define GRL_LOG_DOMAIN(domain) GrlLogDomain *domain = NULL
+
+/**
+ * GRL_LOG_DOMAIN_EXTERN:
+ * @domain: the log domain
+ *
+ * Declares a GrlLogDomain variable as extern. Use in header files.
+ * This macro expands to nothing if debugging is disabled.
+ */
+#define GRL_LOG_DOMAIN_EXTERN(domain) extern GrlLogDomain *domain
+
+/**
+ * GRL_LOG_DOMAIN_STATIC:
+ * @domain: the log domain
+ *
+ * Defines a static GrlLogDomain variable.
+ * This macro expands to nothing if debugging is disabled.
+ */
+#define GRL_LOG_DOMAIN_STATIC(domain) static GrlLogDomain *domain = NULL
+
+/**
+ * GRL_LOG_DOMAIN_INIT:
+ * @domain: the log domain to initialize.
+ * @name: the name of the log domain.
+ *
+ * Creates a new #GrlLogDomain with the given name.
+ * This macro expands to nothing if debugging is disabled.
+ */
+#define GRL_LOG_DOMAIN_INIT(domain, name) G_STMT_START { \
+  if (domain == NULL)                                    \
+    domain = grl_log_domain_new (name);                  \
+} G_STMT_END
+
+/**
+ * GRL_LOG_DOMAIN_FREE:
+ * @domain: the log domain to free.
+ *
+ * Creates a new #GrlLogDomain with the given name and registers it to the
+ * logging system.
+ * This macro expands to nothing if debugging is disabled.
+ */
+#define GRL_LOG_DOMAIN_FREE(domain) G_STMT_START {  \
+  grl_log_domain_free (domain);                     \
+  domain = NULL;                                    \
+} G_STMT_END
+
+/**
+ * GRL_LOG:
+ * @domain: the log domain to use
+ * @level: the severity of the message
+ * @...: A printf-style message to output
+ *
+ * Outputs a debugging message. This is the most general macro for outputting
+ * debugging messages. You will probably want to use one of the ones described
+ * below.
+ */
+#ifdef G_HAVE_ISO_VARARGS
+
+#define GRL_LOG(domain, level, ...) G_STMT_START{       \
+    grl_log ((domain), (level), G_STRLOC, __VA_ARGS__); \
+}G_STMT_END
+
+#elif G_HAVE_GNUC_VARARGS
+
+#define GRL_LOG(domain, level, args...) G_STMT_START{ \
+    grl_log ((domain), (level), G_STRLOC, ##args);    \
+}G_STMT_END
+
+#else /* no variadic macros, use inline */
+
+static inline void
+GRL_LOG_valist (GrlLogDomain *domain,
+                GrlLogLevel   level,
+                const char   *format,
+                va_list       varargs)
+{
+  grl_log (domain, level, "", format, varargs);
+}
+
+static inline void
+GRL_LOG (GrlLogDomain *domain,
+         GrlLogLevel   level,
+         const char   *format,
+         ...)
+{
+  va_list varargs;
+
+  va_start (varargs, format);
+  GRL_LOG_DOMAIN_LOG_valist (domain, level, format, varargs);
+  va_end (varargs);
+}
+
+#endif /* G_HAVE_ISO_VARARGS */
+
+/**
+ * GRL_ERROR:
+ * @...: printf-style message to output
+ *
+ * Output an error message in the default log domain.
+ */
+/**
+ * GRL_WARNING:
+ * @...: printf-style message to output
+ *
+ * Output a warning message in the default log domain.
+ */
+/**
+ * GRL_MESSAGE:
+ * @...: printf-style message to output
+ *
+ * Output a logging message in the default log domain.
+ */
+/**
+ * GRL_INFO:
+ * @...: printf-style message to output
+ *
+ * Output an informational message in the default log domain.
+ */
+/**
+ * GRL_DEBUG:
+ * @...: printf-style message to output
+ *
+ * Output a debugging message in the default log domain.
+ */
+
+#if G_HAVE_ISO_VARARGS
+
+#define GRL_ERROR(...) \
+  GRL_LOG (GRL_LOG_DOMAIN_DEFAULT, GRL_LOG_LEVEL_ERROR, __VA_ARGS__)
+#define GRL_WARNING(...) \
+  GRL_LOG (GRL_LOG_DOMAIN_DEFAULT, GRL_LOG_LEVEL_WARNING, __VA_ARGS__)
+#define GRL_MESSAGE(...) \
+  GRL_LOG (GRL_LOG_DOMAIN_DEFAULT, GRL_LOG_LEVEL_MESSAGE, __VA_ARGS__)
+#define GRL_INFO(...) \
+  GRL_LOG (GRL_LOG_DOMAIN_DEFAULT, GRL_LOG_LEVEL_INFO, __VA_ARGS__)
+#define GRL_DEBUG(...) \
+  GRL_LOG (GRL_LOG_DOMAIN_DEFAULT, GRL_LOG_LEVEL_DEBUG, __VA_ARGS__)
+
+#elif G_HAVE_GNUC_VARARGS
+
+#define GRL_ERROR(args...) \
+  GRL_LOG (GRL_LOG_DOMAIN_DEFAULT, GRL_LOG_LEVEL_ERROR, ##args)
+#define GRL_WARNING(args...) \
+  GRL_LOG (GRL_LOG_DOMAIN_DEFAULT, GRL_LOG_LEVEL_WARNING, ##args)
+#define GRL_MESSAGE(args...) \
+  GRL_LOG (GRL_LOG_DOMAIN_DEFAULT, GRL_LOG_LEVEL_MESSAGE, ##args)
+#define GRL_INFO(args...) \
+  GRL_LOG (GRL_LOG_DOMAIN_DEFAULT, GRL_LOG_LEVEL_INFO, ##args)
+#define GRL_DEBUG(args...) \
+  GRL_LOG (GRL_LOG_DOMAIN_DEFAULT, GRL_LOG_LEVEL_DEBUG, ##args)
+
+#else /* no variadic macros, use inline */
+
+static inline void
+GRL_ERROR (GrlLogDomain *domain, const char *format, ...)
+{
+  va_list varargs;
+
+  va_start (varargs, format);
+  GRL_LOG_valist (domain, GRL_LOG_LEVEL_ERROR, format, varargs);
+  va_end (varargs);
+}
+
+static inline void
+GRL_WARNING (GrlLogDomain *domain, const char *format, ...)
+{
+  va_list varargs;
+
+  va_start (varargs, format);
+  GRL_LOG_valist (domain, GRL_LOG_LEVEL_WARNING, format, varargs);
+  va_end (varargs);
+}
+
+static inline void
+GRL_MESSAGE (GrlLogDomain *domain, const char *format, ...)
+{
+  va_list varargs;
+
+  va_start (varargs, format);
+  GRL_LOG_valist (domain, GRL_LOG_LEVEL_MESSAGE, format, varargs);
+  va_end (varargs);
+}
+
+static inline void
+GRL_INFO (GrlLogDomain *domain, const char *format, ...)
+{
+  va_list varargs;
+
+  va_start (varargs, format);
+  GRL_LOG_valist (domain, GRL_LOG_LEVEL_INFO, format, varargs);
+  va_end (varargs);
+}
+
+static inline void
+GRL_DEBUG (GrlLogDomain *domain, const char *format, ...)
+{
+  va_list varargs;
+
+  va_start (varargs, format);
+  GRL_LOG_valist (domain, GRL_LOG_LEVEL_DEBUG, format, varargs);
+  va_end (varargs);
+}
+
+#endif /* G_HAVE_ISO_VARARGS */
+
+GrlLogDomain *  grl_log_domain_new    (const gchar *name);
+void            grl_log_domain_free   (GrlLogDomain *domain);
+
+void            grl_log_init          (const gchar  *domains);
+void            grl_log               (GrlLogDomain *domain,
+                                       GrlLogLevel   level,
+                                       const gchar  *strloc,
+                                       const gchar  *format,
+                                       ...) G_GNUC_PRINTF (4, 5) G_GNUC_NO_INSTRUMENT;
 
 G_END_DECLS
 
diff --git a/src/grl-media-plugin.c b/src/grl-media-plugin.c
index fcc4a45..71fbe06 100644
--- a/src/grl-media-plugin.c
+++ b/src/grl-media-plugin.c
@@ -36,11 +36,12 @@
 #include "grl-media-plugin.h"
 #include "grl-media-plugin-priv.h"
 #include "grl-plugin-registry.h"
+#include "grl-log.h"
 
 #include <string.h>
 
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "grl-media-plugin"
+#define GRL_LOG_DOMAIN_DEFAULT  media_plugin_log_domain
+GRL_LOG_DOMAIN(media_plugin_log_domain);
 
 #define GRL_MEDIA_PLUGIN_GET_PRIVATE(object)            \
   (G_TYPE_INSTANCE_GET_PRIVATE((object),                \
diff --git a/src/grl-media-source.c b/src/grl-media-source.c
index d75d7ee..5892a13 100644
--- a/src/grl-media-source.c
+++ b/src/grl-media-source.c
@@ -45,11 +45,12 @@
 #include "data/grl-media.h"
 #include "data/grl-media-box.h"
 #include "grl-error.h"
+#include "grl-log.h"
 
 #include <string.h>
 
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "grl-media-source"
+#define GRL_LOG_DOMAIN_DEFAULT  media_source_log_domain
+GRL_LOG_DOMAIN(media_source_log_domain);
 
 #define GRL_MEDIA_SOURCE_GET_PRIVATE(object)            \
   (G_TYPE_INSTANCE_GET_PRIVATE((object),                \
@@ -270,7 +271,7 @@ grl_media_source_finalize (GObject *object)
 {
   GrlMediaSource *source;
 
-  g_debug ("grl_media_source_finalize");
+  GRL_DEBUG ("grl_media_source_finalize");
 
   source = GRL_MEDIA_SOURCE (object);
 
@@ -292,7 +293,7 @@ grl_media_source_finalize (GObject *object)
 static void
 set_operation_finished (GrlMediaSource *source, guint operation_id)
 {
-  g_debug ("set_operation_finished (%d)", operation_id);
+  GRL_DEBUG ("set_operation_finished (%d)", operation_id);
   g_hash_table_remove (source->priv->pending_operations,
 		       GINT_TO_POINTER (operation_id));
 }
@@ -301,7 +302,7 @@ static void
 set_operation_completed (GrlMediaSource *source, guint operation_id)
 {
   struct OperationState *op_state;
-  g_debug ("set_operation_completed (%d)", operation_id);
+  GRL_DEBUG ("set_operation_completed (%d)", operation_id);
   op_state = g_hash_table_lookup (source->priv->pending_operations,
 				  GINT_TO_POINTER (operation_id));
   if (op_state) {
@@ -313,7 +314,7 @@ static void
 set_operation_cancelled (GrlMediaSource *source, guint operation_id)
 {
   struct OperationState *op_state;
-  g_debug ("set_operation_cancelled (%d)", operation_id);
+  GRL_DEBUG ("set_operation_cancelled (%d)", operation_id);
   op_state = g_hash_table_lookup (source->priv->pending_operations,
 				  GINT_TO_POINTER (operation_id));
   if (op_state) {
@@ -326,7 +327,7 @@ set_operation_ongoing (GrlMediaSource *source, guint operation_id)
 {
   struct OperationState *op_state;
 
-  g_debug ("set_operation_ongoing (%d)", operation_id);
+  GRL_DEBUG ("set_operation_ongoing (%d)", operation_id);
 
   op_state = g_new0 (struct OperationState, 1);
   g_hash_table_insert (source->priv->pending_operations,
@@ -379,7 +380,7 @@ get_operation_data (GrlMediaSource *source, guint operation_id)
   if (op_state) {
     return op_state->data;
   } else {
-    g_warning ("Tried to get operation data but operation does not exist");
+    GRL_WARNING ("Tried to get operation data but operation does not exist");
     return NULL;
   }
 }
@@ -389,21 +390,21 @@ set_operation_data (GrlMediaSource *source, guint operation_id, gpointer data)
 {
   struct OperationState *op_state;
 
-  g_debug ("set_operation_data");
+  GRL_DEBUG ("set_operation_data");
 
   op_state = g_hash_table_lookup (source->priv->pending_operations,
 				  GINT_TO_POINTER (operation_id));
   if (op_state) {
     op_state->data = data;
   } else {
-    g_warning ("Tried to set operation data but operation does not exist");
+    GRL_WARNING ("Tried to set operation data but operation does not exist");
   }
 }
 
 static void
 free_browse_operation_spec (GrlMediaSourceBrowseSpec *spec)
 {
-  g_debug ("free_browse_operation_spec");
+  GRL_DEBUG ("free_browse_operation_spec");
   g_object_unref (spec->source);
   g_object_unref (spec->container);
   g_list_free (spec->keys);
@@ -413,7 +414,7 @@ free_browse_operation_spec (GrlMediaSourceBrowseSpec *spec)
 static void
 free_search_operation_spec (GrlMediaSourceSearchSpec *spec)
 {
-  g_debug ("free_search_operation_spec");
+  GRL_DEBUG ("free_search_operation_spec");
   g_object_unref (spec->source);
   g_free (spec->text);
   g_list_free (spec->keys);
@@ -423,7 +424,7 @@ free_search_operation_spec (GrlMediaSourceSearchSpec *spec)
 static void
 free_query_operation_spec (GrlMediaSourceQuerySpec *spec)
 {
-  g_debug ("free_query_operation_spec");
+  GRL_DEBUG ("free_query_operation_spec");
   g_object_unref (spec->source);
   g_free (spec->query);
   g_list_free (spec->keys);
@@ -447,13 +448,13 @@ free_source_map_list (GList *source_map_list)
 static gboolean
 browse_idle (gpointer user_data)
 {
-  g_debug ("browse_idle");
+  GRL_DEBUG ("browse_idle");
   GrlMediaSourceBrowseSpec *bs = (GrlMediaSourceBrowseSpec *) user_data;
   /* Check if operation was cancelled even before the idle kicked in */
   if (!operation_is_cancelled (bs->source, bs->browse_id)) {
     GRL_MEDIA_SOURCE_GET_CLASS (bs->source)->browse (bs->source, bs);
   } else {
-    g_debug ("  operation was cancelled");
+    GRL_DEBUG ("  operation was cancelled");
     bs->callback (bs->source, bs->browse_id, NULL, 0, bs->user_data, NULL);
   }
   return FALSE;
@@ -462,13 +463,13 @@ browse_idle (gpointer user_data)
 static gboolean
 search_idle (gpointer user_data)
 {
-  g_debug ("search_idle");
+  GRL_DEBUG ("search_idle");
   GrlMediaSourceSearchSpec *ss = (GrlMediaSourceSearchSpec *) user_data;
   /* Check if operation was cancelled even before the idle kicked in */
   if (!operation_is_cancelled (ss->source, ss->search_id)) {
     GRL_MEDIA_SOURCE_GET_CLASS (ss->source)->search (ss->source, ss);
   } else {
-    g_debug ("  operation was cancelled");
+    GRL_DEBUG ("  operation was cancelled");
     ss->callback (ss->source, ss->search_id, NULL, 0, ss->user_data, NULL);
   }
   return FALSE;
@@ -477,12 +478,12 @@ search_idle (gpointer user_data)
 static gboolean
 query_idle (gpointer user_data)
 {
-  g_debug ("query_idle");
+  GRL_DEBUG ("query_idle");
   GrlMediaSourceQuerySpec *qs = (GrlMediaSourceQuerySpec *) user_data;
   if (!operation_is_cancelled (qs->source, qs->query_id)) {
     GRL_MEDIA_SOURCE_GET_CLASS (qs->source)->query (qs->source, qs);
   } else {
-    g_debug ("  operation was cancelled");
+    GRL_DEBUG ("  operation was cancelled");
     qs->callback (qs->source, qs->query_id, NULL, 0, qs->user_data, NULL);
   }
   return FALSE;
@@ -491,12 +492,12 @@ query_idle (gpointer user_data)
 static gboolean
 metadata_idle (gpointer user_data)
 {
-  g_debug ("metadata_idle");
+  GRL_DEBUG ("metadata_idle");
   GrlMediaSourceMetadataSpec *ms = (GrlMediaSourceMetadataSpec *) user_data;
   if (!operation_is_cancelled (ms->source, ms->metadata_id)) {
     GRL_MEDIA_SOURCE_GET_CLASS (ms->source)->metadata (ms->source, ms);
   } else {
-    g_debug ("  operation was cancelled");
+    GRL_DEBUG ("  operation was cancelled");
     ms->callback (ms->source, ms->media, ms->user_data, NULL);
   }
   return FALSE;
@@ -516,7 +517,7 @@ store_idle_destroy (gpointer user_data)
 static gboolean
 store_idle (gpointer user_data)
 {
-  g_debug ("store_idle");
+  GRL_DEBUG ("store_idle");
   GrlMediaSourceStoreSpec *ss = (GrlMediaSourceStoreSpec *) user_data;
   GRL_MEDIA_SOURCE_GET_CLASS (ss->source)->store (ss->source, ss);
   return FALSE;
@@ -534,7 +535,7 @@ remove_idle_destroy (gpointer user_data)
 static gboolean
 remove_idle (gpointer user_data)
 {
-  g_debug ("remove_idle");
+  GRL_DEBUG ("remove_idle");
   GrlMediaSourceRemoveSpec *rs = (GrlMediaSourceRemoveSpec *) user_data;
   GRL_MEDIA_SOURCE_GET_CLASS (rs->source)->remove (rs->source, rs);
   return FALSE;
@@ -543,7 +544,7 @@ remove_idle (gpointer user_data)
 static gboolean
 browse_result_relay_idle (gpointer user_data)
 {
-  g_debug ("browse_result_relay_idle");
+  GRL_DEBUG ("browse_result_relay_idle");
 
   struct BrowseRelayIdle *bri = (struct BrowseRelayIdle *) user_data;
   gboolean cancelled = FALSE;
@@ -566,7 +567,7 @@ browse_result_relay_idle (gpointer user_data)
 			bri->user_data,
 			bri->error);
   } else {
-    g_debug ("operation was cancelled, skipping idle result!");
+    GRL_DEBUG ("operation was cancelled, skipping idle result!");
   }
 
   if (bri->remaining == 0 && !bri->chained) {
@@ -620,8 +621,8 @@ auto_split_run_next_chunk (struct BrowseRelayCb *brc, guint remaining)
     as_info->chunk_requested = remaining;
   }
   *count = as_info->chunk_requested;
-  g_debug ("auto-split: requesting next chunk (skip=%u, count=%u)",
-	   *skip, *count);
+  GRL_DEBUG ("auto-split: requesting next chunk (skip=%u, count=%u)",
+             *skip, *count);
   g_idle_add (operation, spec);
 }
 
@@ -636,10 +637,10 @@ browse_result_relay_cb (GrlMediaSource *source,
   struct BrowseRelayCb *brc;
   guint plugin_remaining = remaining;
 
-  g_debug ("browse_result_relay_cb, op:%u, source:%s, remaining:%u",
-	   browse_id,
-	   grl_metadata_source_get_name (GRL_METADATA_SOURCE (source)),
-	   remaining);
+  GRL_DEBUG ("browse_result_relay_cb, op:%u, source:%s, remaining:%u",
+             browse_id,
+             grl_metadata_source_get_name (GRL_METADATA_SOURCE (source)),
+             remaining);
 
   brc = (struct BrowseRelayCb *) user_data;
 
@@ -650,7 +651,7 @@ browse_result_relay_cb (GrlMediaSource *source,
   /* Check if operation is still valid , otherwise do not emit the result
      but make sure to free the operation data when remaining is 0 */
   if (!operation_is_ongoing (source, browse_id)) {
-    g_debug ("operation is cancelled or already finished, skipping result!");
+    GRL_DEBUG ("operation is cancelled or already finished, skipping result!");
     if (media) {
       g_object_unref (media);
       media = NULL;
@@ -669,10 +670,10 @@ browse_result_relay_cb (GrlMediaSource *source,
 	 have the chance to free their resources. If the operation is already
 	 completed (includes finished) however, we already let the last
 	 result through and doing it again would cause a crash */
-      g_warning ("Source '%s' emitted 'remaining=0' more than once " \
-		 "for operation %d",
-		 grl_metadata_source_get_name (GRL_METADATA_SOURCE (source)),
-		 browse_id);
+      GRL_WARNING ("Source '%s' emitted 'remaining=0' more than once for "
+                   "operation %d",
+                   grl_metadata_source_get_name (GRL_METADATA_SOURCE (source)),
+                   browse_id);
       return;
     }
     /* If we reached this point the operation is cancelled but not completed
@@ -751,8 +752,9 @@ browse_result_relay_cb (GrlMediaSource *source,
 
   /* Free callback data when we processed the last result */
   if (remaining == 0) {
-    g_debug ("Got remaining '0' for operation %d (%s)",
-	     browse_id,  grl_metadata_source_get_name (GRL_METADATA_SOURCE (source)));
+    GRL_DEBUG ("Got remaining '0' for operation %d (%s)",
+               browse_id,
+               grl_metadata_source_get_name (GRL_METADATA_SOURCE (source)));
     if (brc->bspec) {
       free_browse_operation_spec (brc->bspec);
     } else if (brc->sspec) {
@@ -775,7 +777,7 @@ multiple_result_async_cb (GrlMediaSource *source,
 {
   GrlDataSync *ds = (GrlDataSync *) user_data;
 
-  g_debug ("multiple_result_async_cb");
+  GRL_DEBUG ("multiple_result_async_cb");
 
   if (error) {
     ds->error = g_error_copy (error);
@@ -805,7 +807,7 @@ metadata_result_relay_cb (GrlMediaSource *source,
 			  gpointer user_data,
 			  const GError *error)
 {
-  g_debug ("metadata_result_relay_cb");
+  GRL_DEBUG ("metadata_result_relay_cb");
 
   struct MetadataRelayCb *mrc;
 
@@ -835,7 +837,7 @@ metadata_result_async_cb (GrlMediaSource *source,
 {
   GrlDataSync *ds = (GrlDataSync *) user_data;
 
-  g_debug ("metadata_result_async_cb");
+  GRL_DEBUG ("metadata_result_async_cb");
 
   if (error) {
     ds->error = g_error_copy (error);
@@ -854,7 +856,7 @@ store_async_cb (GrlMediaSource *source,
 {
   GrlDataSync *ds = (GrlDataSync *) user_data;
 
-  g_debug ("store_async_cb");
+  GRL_DEBUG ("store_async_cb");
 
   if (error) {
     ds->error = g_error_copy (error);
@@ -871,7 +873,7 @@ remove_async_cb (GrlMediaSource *source,
 {
   GrlDataSync *ds = (GrlDataSync *) user_data;
 
-  g_debug ("remove_async_cb");
+  GRL_DEBUG ("remove_async_cb");
 
   if (error) {
     ds->error = g_error_copy (error);
@@ -946,7 +948,7 @@ full_resolution_done_cb (GrlMetadataSource *source,
 			 gpointer user_data,
 			 const GError *error)
 {
-  g_debug ("full_resolution_done_cb");
+  GRL_DEBUG ("full_resolution_done_cb");
 
   gboolean cancelled = FALSE;
   struct FullResolutionCtlCb *ctl_info;
@@ -962,7 +964,7 @@ full_resolution_done_cb (GrlMetadataSource *source,
      source though, it means the error was provided by the control callback
      and in that case we have to emit it */
   if (error && source) {
-    g_warning ("Failed to fully resolve some metadata: %s", error->message);
+    GRL_WARNING ("Failed to fully resolve some metadata: %s", error->message);
     error = NULL;
   }
 
@@ -972,7 +974,8 @@ full_resolution_done_cb (GrlMetadataSource *source,
     /* But check if operation was cancelled (or even finished) before emitting
        (we execute in the idle loop) */
     if (operation_is_cancelled (cb_info->source, cb_info->browse_id)) {
-      g_debug ("operation was cancelled, skipping full resolution done result!");
+      GRL_DEBUG ("operation was cancelled, skipping full resolution done "
+                 "result!");
       if (media) {
 	g_object_unref (media);
 	media = NULL;
@@ -990,7 +993,7 @@ full_resolution_done_cb (GrlMetadataSource *source,
 	/* Notice we pass NULL as error on purpose
 	   since the result is valid even if the full-resolution failed */
 	guint remaining = cb_info->remaining;
-	g_debug ("  Result is in sort order, emitting (%d)", remaining);
+	GRL_DEBUG ("  Result is in sort order, emitting (%d)", remaining);
 	ctl_info->user_callback (cb_info->source,
 				 cb_info->browse_id,
 				 media,
@@ -1037,7 +1040,7 @@ full_resolution_ctl_cb (GrlMediaSource *source,
   struct FullResolutionCtlCb *ctl_info =
     (struct FullResolutionCtlCb *) user_data;
 
-  g_debug ("full_resolution_ctl_cb");
+  GRL_DEBUG ("full_resolution_ctl_cb");
 
   /* No need to check if the operation is cancelled, that was
      already checked in the relay callback and this is called
@@ -1081,7 +1084,7 @@ full_resolution_ctl_cb (GrlMediaSource *source,
       gchar *name;
       struct SourceKeyMap *map = (struct SourceKeyMap *) iter->data;
       g_object_get (map->source, "source-name", &name, NULL);
-      g_debug ("Using '%s' to resolve extra metadata now", name);
+      GRL_DEBUG ("Using '%s' to resolve extra metadata now", name);
 
       grl_metadata_source_resolve (map->source,
                                    map->keys,
@@ -1101,7 +1104,7 @@ metadata_full_resolution_done_cb (GrlMetadataSource *source,
 				  gpointer user_data,
 				  const GError *error)
 {
-  g_debug ("metadata_full_resolution_done_cb");
+  GRL_DEBUG ("metadata_full_resolution_done_cb");
 
   struct MetadataFullResolutionDoneCb *cb_info =
     (struct MetadataFullResolutionDoneCb *) user_data;
@@ -1109,7 +1112,7 @@ metadata_full_resolution_done_cb (GrlMetadataSource *source,
   cb_info->pending_callbacks--;
 
   if (error) {
-    g_warning ("Failed to fully resolve some metadata: %s", error->message);
+    GRL_WARNING ("Failed to fully resolve some metadata: %s", error->message);
   }
 
   if (cb_info->pending_callbacks == 0) {
@@ -1135,11 +1138,11 @@ metadata_full_resolution_ctl_cb (GrlMediaSource *source,
   struct MetadataFullResolutionCtlCb *ctl_info =
     (struct MetadataFullResolutionCtlCb *) user_data;
 
-  g_debug ("metadata_full_resolution_ctl_cb");
+  GRL_DEBUG ("metadata_full_resolution_ctl_cb");
 
   /* If we got an error, invoke the user callback right away and bail out */
   if (error) {
-    g_warning ("Operation failed: %s", error->message);
+    GRL_WARNING ("Operation failed: %s", error->message);
     ctl_info->user_callback (source,
 			     media,
 			     ctl_info->user_data,
@@ -1164,7 +1167,7 @@ metadata_full_resolution_ctl_cb (GrlMediaSource *source,
     gchar *name;
     struct SourceKeyMap *map = (struct SourceKeyMap *) iter->data;
     g_object_get (map->source, "source-name", &name, NULL);
-    g_debug ("Using '%s' to resolve extra metadata now", name);
+    GRL_DEBUG ("Using '%s' to resolve extra metadata now", name);
 
     grl_metadata_source_resolve (map->source,
                                  map->keys,
@@ -1228,7 +1231,7 @@ grl_media_source_browse (GrlMediaSource *source,
   _user_data = user_data;
 
   if (flags & GRL_RESOLVE_FAST_ONLY) {
-    g_debug ("requested fast keys only");
+    GRL_DEBUG ("requested fast keys only");
     grl_metadata_source_filter_slow (GRL_METADATA_SOURCE (source),
                                      &_keys,
                                      FALSE);
@@ -1236,7 +1239,7 @@ grl_media_source_browse (GrlMediaSource *source,
 
   /* Setup full resolution mode if requested */
   if (flags & GRL_RESOLVE_FULL) {
-    g_debug ("requested full resolution");
+    GRL_DEBUG ("requested full resolution");
     grl_metadata_source_setup_full_resolution_mode (GRL_METADATA_SOURCE (source),
                                                     NULL, _keys, &key_mapping);
 
@@ -1297,7 +1300,7 @@ grl_media_source_browse (GrlMediaSource *source,
   /* Setup auto-split management if requested */
   if (source->priv->auto_split_threshold > 0 &&
       count > source->priv->auto_split_threshold) {
-    g_debug ("auto-split: enabled");
+    GRL_DEBUG ("auto-split: enabled");
     struct AutoSplitCtl *as_ctl = g_new0 (struct AutoSplitCtl, 1);
     as_ctl->count = count;
     as_ctl->threshold = source->priv->auto_split_threshold;
@@ -1305,8 +1308,8 @@ grl_media_source_browse (GrlMediaSource *source,
     as_ctl->chunk_first = TRUE;
     bs->count = as_ctl->chunk_requested;
     brc->auto_split = as_ctl;
-    g_debug ("auto-split: requesting first chunk (skip=%u, count=%u)",
-	     bs->skip, bs->count);
+    GRL_DEBUG ("auto-split: requesting first chunk (skip=%u, count=%u)",
+               bs->skip, bs->count);
   }
 
   set_operation_ongoing (source, browse_id);
@@ -1421,12 +1424,12 @@ grl_media_source_search (GrlMediaSource *source,
   _keys = g_list_copy ((GList *) keys);
 
   if (flags & GRL_RESOLVE_FAST_ONLY) {
-    g_debug ("requested fast keys only");
+    GRL_DEBUG ("requested fast keys only");
     grl_metadata_source_filter_slow (GRL_METADATA_SOURCE (source), &_keys, FALSE);
   }
 
   if (flags & GRL_RESOLVE_FULL) {
-    g_debug ("requested full search");
+    GRL_DEBUG ("requested full search");
     grl_metadata_source_setup_full_resolution_mode (GRL_METADATA_SOURCE (source),
                                                     NULL, _keys, &key_mapping);
 
@@ -1478,7 +1481,7 @@ grl_media_source_search (GrlMediaSource *source,
   /* Setup auto-split management if requested */
   if (source->priv->auto_split_threshold > 0 &&
       count > source->priv->auto_split_threshold) {
-    g_debug ("auto-split: enabled");
+    GRL_DEBUG ("auto-split: enabled");
     struct AutoSplitCtl *as_ctl = g_new0 (struct AutoSplitCtl, 1);
     as_ctl->count = count;
     as_ctl->threshold = source->priv->auto_split_threshold;
@@ -1486,8 +1489,8 @@ grl_media_source_search (GrlMediaSource *source,
     as_ctl->chunk_first = TRUE;
     ss->count = as_ctl->chunk_requested;
     brc->auto_split = as_ctl;
-    g_debug ("auto-split: requesting first chunk (skip=%u, count=%u)",
-	     ss->skip, ss->count);
+    GRL_DEBUG ("auto-split: requesting first chunk (skip=%u, count=%u)",
+               ss->skip, ss->count);
   }
 
   set_operation_ongoing (source, search_id);
@@ -1607,14 +1610,14 @@ grl_media_source_query (GrlMediaSource *source,
   _keys = g_list_copy ((GList *) keys);
 
   if (flags & GRL_RESOLVE_FAST_ONLY) {
-    g_debug ("requested fast keys only");
+    GRL_DEBUG ("requested fast keys only");
     grl_metadata_source_filter_slow (GRL_METADATA_SOURCE (source),
                                      &_keys,
                                      FALSE);
   }
 
   if (flags & GRL_RESOLVE_FULL) {
-    g_debug ("requested full search");
+    GRL_DEBUG ("requested full search");
     grl_metadata_source_setup_full_resolution_mode (GRL_METADATA_SOURCE (source),
                                                     NULL, _keys, &key_mapping);
 
@@ -1666,7 +1669,7 @@ grl_media_source_query (GrlMediaSource *source,
   /* Setup auto-split management if requested */
   if (source->priv->auto_split_threshold > 0 &&
       count > source->priv->auto_split_threshold) {
-    g_debug ("auto-split: enabled");
+    GRL_DEBUG ("auto-split: enabled");
     struct AutoSplitCtl *as_ctl = g_new0 (struct AutoSplitCtl, 1);
     as_ctl->count = count;
     as_ctl->threshold = source->priv->auto_split_threshold;
@@ -1674,8 +1677,8 @@ grl_media_source_query (GrlMediaSource *source,
     as_ctl->chunk_first = TRUE;
     qs->count = as_ctl->chunk_requested;
     brc->auto_split = as_ctl;
-    g_debug ("auto-split: requesting first chunk (skip=%u, count=%u)",
-	     qs->skip, qs->count);
+    GRL_DEBUG ("auto-split: requesting first chunk (skip=%u, count=%u)",
+               qs->skip, qs->count);
   }
 
   set_operation_ongoing (source, query_id);
@@ -1772,7 +1775,7 @@ grl_media_source_metadata (GrlMediaSource *source,
   struct MetadataRelayCb *mrc;
   guint metadata_id;
 
-  g_debug ("grl_media_source_metadata");
+  GRL_DEBUG ("grl_media_source_metadata");
 
   g_return_val_if_fail (GRL_IS_MEDIA_SOURCE (source), 0);
   g_return_val_if_fail (keys != NULL, 0);
@@ -1791,7 +1794,7 @@ grl_media_source_metadata (GrlMediaSource *source,
   }
 
   if (flags & GRL_RESOLVE_FULL) {
-    g_debug ("requested full metadata");
+    GRL_DEBUG ("requested full metadata");
     grl_metadata_source_setup_full_resolution_mode (GRL_METADATA_SOURCE (source),
                                                     media, _keys, &key_mapping);
 
@@ -1943,13 +1946,13 @@ grl_media_source_supported_operations (GrlMetadataSource *metadata_source)
 void
 grl_media_source_cancel (GrlMediaSource *source, guint operation_id)
 {
-  g_debug ("grl_media_source_cancel");
+  GRL_DEBUG ("grl_media_source_cancel");
 
   g_return_if_fail (GRL_IS_MEDIA_SOURCE (source));
 
   if (!operation_is_ongoing (source, operation_id)) {
-    g_debug ("Tried to cancel invalid or already cancelled "\
-	     "operation. Skipping...");
+    GRL_DEBUG ("Tried to cancel invalid or already cancelled operation. "
+               "Skipping...");
     return;
   }
 
@@ -1982,7 +1985,7 @@ grl_media_source_set_operation_data (GrlMediaSource *source,
                                      guint operation_id,
                                      gpointer data)
 {
-  g_debug ("grl_media_source_set_operation_data");
+  GRL_DEBUG ("grl_media_source_set_operation_data");
   g_return_if_fail (GRL_IS_MEDIA_SOURCE (source));
   set_operation_data (source, operation_id, data);
 }
@@ -2000,7 +2003,7 @@ gpointer
 grl_media_source_get_operation_data (GrlMediaSource *source,
                                      guint operation_id)
 {
-  g_debug ("grl_media_source_get_operation_data");
+  GRL_DEBUG ("grl_media_source_get_operation_data");
   g_return_val_if_fail (GRL_IS_MEDIA_SOURCE (source), NULL);
   return get_operation_data (source, operation_id);
 }
@@ -2054,7 +2057,7 @@ grl_media_source_store (GrlMediaSource *source,
                         GrlMediaSourceStoreCb callback,
                         gpointer user_data)
 {
-  g_debug ("grl_media_source_store");
+  GRL_DEBUG ("grl_media_source_store");
 
   const gchar *title;
   const gchar *url;
@@ -2161,7 +2164,7 @@ grl_media_source_remove (GrlMediaSource *source,
                          GrlMediaSourceRemoveCb callback,
                          gpointer user_data)
 {
-  g_debug ("grl_media_source_remove");
+  GRL_DEBUG ("grl_media_source_remove");
 
   const gchar *id;
   GError *error = NULL;
diff --git a/src/grl-metadata-source.c b/src/grl-metadata-source.c
index 63557e5..4ec06ff 100644
--- a/src/grl-metadata-source.c
+++ b/src/grl-metadata-source.c
@@ -48,12 +48,13 @@
 #include "grl-sync-priv.h"
 #include "grl-plugin-registry.h"
 #include "grl-error.h"
+#include "grl-log.h"
 #include "data/grl-media.h"
 
 #include <string.h>
 
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "grl-metadata-source"
+#define GRL_LOG_DOMAIN_DEFAULT  metadata_source_log_domain
+GRL_LOG_DOMAIN(metadata_source_log_domain);
 
 #define GRL_METADATA_SOURCE_GET_PRIVATE(object)                 \
   (G_TYPE_INSTANCE_GET_PRIVATE((object),                        \
@@ -182,7 +183,7 @@ grl_metadata_source_finalize (GObject *object)
 {
   GrlMetadataSource *source;
 
-  g_debug ("grl_metadata_source_finalize");
+  GRL_DEBUG ("grl_metadata_source_finalize");
 
   source = GRL_METADATA_SOURCE (object);
 
@@ -270,7 +271,7 @@ print_keys (gchar *label, const GList *keys)
 static void
 free_set_metadata_ctl_cb_info (struct SetMetadataCtlCb *data)
 {
-  g_debug ("free_set_metadata_ctl_cb_info");
+  GRL_DEBUG ("free_set_metadata_ctl_cb_info");
 
   GList *iter;
   g_object_unref (data->source);
@@ -301,7 +302,7 @@ set_metadata_ctl_cb (GrlMetadataSource *source,
 		     gpointer user_data,
 		     const GError *error)
 {
-  g_debug ("set_metadata_ctl_cb");
+  GRL_DEBUG ("set_metadata_ctl_cb");
 
   struct SetMetadataCtlCb *smctlcb;
   GError *own_error = NULL;
@@ -339,7 +340,7 @@ resolve_result_relay_cb (GrlMetadataSource *source,
 			 gpointer user_data,
 			 const GError *error)
 {
-  g_debug ("resolve_result_relay_cb");
+  GRL_DEBUG ("resolve_result_relay_cb");
 
   struct ResolveRelayCb *rrc;
 
@@ -356,7 +357,7 @@ resolve_result_relay_cb (GrlMetadataSource *source,
 static gboolean
 resolve_idle (gpointer user_data)
 {
-  g_debug ("resolve_idle");
+  GRL_DEBUG ("resolve_idle");
   GrlMetadataSourceResolveSpec *rs =
     (GrlMetadataSourceResolveSpec *) user_data;
   GRL_METADATA_SOURCE_GET_CLASS (rs->source)->resolve (rs->source, rs);
@@ -371,7 +372,7 @@ resolve_result_async_cb (GrlMetadataSource *source,
 {
   GrlDataSync *ds = (GrlDataSync *) user_data;
 
-  g_debug ("resolve_result_async_cb");
+  GRL_DEBUG ("resolve_result_async_cb");
 
   if (error) {
     ds->error = g_error_copy (error);
@@ -390,7 +391,7 @@ set_metadata_result_async_cb (GrlMetadataSource *source,
 {
   GrlDataSync *ds = (GrlDataSync *) user_data;
 
-  g_debug ("resolve_result_async_cb");
+  GRL_DEBUG ("resolve_result_async_cb");
 
   if (error) {
     ds->error = g_error_copy (error);
@@ -403,7 +404,7 @@ set_metadata_result_async_cb (GrlMetadataSource *source,
 static gboolean
 set_metadata_idle (gpointer user_data)
 {
-  g_debug ("set_metadata_idle");
+  GRL_DEBUG ("set_metadata_idle");
 
   GrlMetadataSourceSetMetadataSpec *sms;
   struct SetMetadataCtlCb *smctlcb;
@@ -598,7 +599,7 @@ grl_metadata_source_resolve (GrlMetadataSource *source,
   GList *_keys;
   struct ResolveRelayCb *rrc;
 
-  g_debug ("grl_metadata_source_resolve");
+  GRL_DEBUG ("grl_metadata_source_resolve");
 
   g_return_if_fail (GRL_IS_METADATA_SOURCE (source));
   g_return_if_fail (callback != NULL);
@@ -894,7 +895,7 @@ grl_metadata_source_setup_full_resolution_mode (GrlMetadataSource *source,
     grl_metadata_source_filter_supported (source, &key_list, TRUE);
 
   if (key_list == NULL) {
-    g_debug ("Source supports all requested keys");
+    GRL_DEBUG ("Source supports all requested keys");
     goto done;
   }
 
@@ -942,16 +943,16 @@ grl_metadata_source_setup_full_resolution_mode (GrlMetadataSource *source,
 
     /* Check if this source supports some of the missing keys */
     g_object_get (_source, "source-name", &name, NULL);
-    g_debug ("Checking resolution capabilities for source '%s'", name);
+    GRL_DEBUG ("Checking resolution capabilities for source '%s'", name);
     supported_keys = grl_metadata_source_filter_supported (_source,
                                                            &key_list, TRUE);
 
     if (!supported_keys) {
-      g_debug ("  Source does not support any of the keys, skipping.");
+      GRL_DEBUG ("  Source does not support any of the keys, skipping.");
       continue;
     }
 
-    g_debug ("  '%s' can resolve some keys, checking deps", name);
+    GRL_DEBUG ("  '%s' can resolve some keys, checking deps", name);
 
     /* Check the external dependencies for these supported keys */
     GList *supported_deps;
@@ -968,16 +969,16 @@ grl_metadata_source_setup_full_resolution_mode (GrlMetadataSource *source,
       /* deps == NULL means the key cannot be resolved
 	 by using only metadata */
       if (!deps) {
-	g_debug ("    Key '%s' cannot be resolved from metadata",
-                 GRL_METADATA_KEY_GET_NAME (key));
+	GRL_DEBUG ("    Key '%s' cannot be resolved from metadata",
+                   GRL_METADATA_KEY_GET_NAME (key));
 	supported_keys = g_list_delete_link (supported_keys, iter_prev);
 	key_list = g_list_prepend (key_list, key);
 	continue;
       }
 
       if (media) {
-        g_debug ("    Key '%s' might be resolved using current media",
-                 GRL_METADATA_KEY_GET_NAME (key));
+        GRL_DEBUG ("    Key '%s' might be resolved using current media",
+                   GRL_METADATA_KEY_GET_NAME (key));
         GList *iter_deps;
         GList *iter_deps_prev;
         iter_deps = deps;
@@ -991,21 +992,21 @@ grl_metadata_source_setup_full_resolution_mode (GrlMetadataSource *source,
           }
         }
         if (!deps) {
-          g_debug ("    Key '%s' can be resolved solely using current media",
-                   GRL_METADATA_KEY_GET_NAME (key));
+          GRL_DEBUG ("    Key '%s' can be resolved solely using current media",
+                     GRL_METADATA_KEY_GET_NAME (key));
           continue;
         }
       }
 
-      g_debug ("    Key '%s' might be resolved using external metadata",
-               GRL_METADATA_KEY_GET_NAME (key));
+      GRL_DEBUG ("    Key '%s' might be resolved using external metadata",
+                 GRL_METADATA_KEY_GET_NAME (key));
 
       /* Check if the original source can solve these dependencies */
       supported_deps =
 	grl_metadata_source_filter_supported (GRL_METADATA_SOURCE (source),
                                               &deps, TRUE);
       if (deps) {
-	g_debug ("      Dependencies not supported by source, dropping key");
+	GRL_DEBUG ("      Dependencies not supported by source, dropping key");
 	/* Maybe some other source can still resolve it */
 	/* TODO: maybe some of the sources already inspected could provide
 	   these keys! */
@@ -1015,7 +1016,7 @@ grl_metadata_source_setup_full_resolution_mode (GrlMetadataSource *source,
 	   resolve it */
 	key_list = g_list_prepend (key_list, key);
       } else {
-	g_debug ("      Dependencies supported by source, including key");
+	GRL_DEBUG ("      Dependencies supported by source, including key");
 	/* Add these dependencies to the list of keys for
 	   the browse operation */
 	/* TODO: maybe some of these keys are in the list already! */
@@ -1026,7 +1027,7 @@ grl_metadata_source_setup_full_resolution_mode (GrlMetadataSource *source,
 
     /* Save the key map for this source */
     if (supported_keys) {
-      g_debug ("  Adding source '%s' to the resolution map", name);
+      GRL_DEBUG ("  Adding source '%s' to the resolution map", name);
       struct SourceKeyMap *source_key_map = g_new (struct SourceKeyMap, 1);
       source_key_map->source = g_object_ref (_source);
       source_key_map->keys = supported_keys;
@@ -1036,7 +1037,7 @@ grl_metadata_source_setup_full_resolution_mode (GrlMetadataSource *source,
   }
 
   if (key_mapping->source_maps == NULL) {
-    g_debug ("No key mapping for other sources, can't resolve more metadata");
+    GRL_DEBUG ("No key mapping for other sources, can't resolve more metadata");
   }
  done:
   return;
@@ -1112,7 +1113,7 @@ grl_metadata_source_set_metadata (GrlMetadataSource *source,
   GError *error;
   struct SetMetadataCtlCb *smctlcb;
 
-  g_debug ("grl_metadata_source_set_metadata");
+  GRL_DEBUG ("grl_metadata_source_set_metadata");
 
   g_return_if_fail (GRL_IS_METADATA_SOURCE (source));
   g_return_if_fail (callback != NULL);
diff --git a/src/grl-multiple.c b/src/grl-multiple.c
index 375e131..4cfc916 100644
--- a/src/grl-multiple.c
+++ b/src/grl-multiple.c
@@ -24,9 +24,10 @@
 #include "grl-sync-priv.h"
 #include "grl-plugin-registry.h"
 #include "grl-error.h"
+#include "grl-log.h"
 
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "grl-multiple"
+#define GRL_LOG_DOMAIN_DEFAULT  multiple_log_domain
+GRL_LOG_DOMAIN(multiple_log_domain);
 
 struct MultipleSearchData {
   GHashTable *table;
@@ -75,7 +76,7 @@ static gint multiple_search_id = 1;
 static void
 free_multiple_search_data (struct MultipleSearchData *msd)
 {
-  g_debug ("free_multiple_search_data");
+  GRL_DEBUG ("free_multiple_search_data");
   g_hash_table_unref (msd->table);
   g_list_free (msd->search_ids);
   g_list_free (msd->sources);
@@ -141,7 +142,7 @@ start_multiple_search_operation (guint search_id,
 				 GrlMediaSourceResultCb user_callback,
 				 gpointer user_data)
 {
-  g_debug ("start_multiple_search_operation");
+  GRL_DEBUG ("start_multiple_search_operation");
   
   struct MultipleSearchData *msd;
   GList *iter_sources, *iter_skips;
@@ -204,9 +205,9 @@ start_multiple_search_operation (guint search_id,
 				    multiple_search_cb,
 				    msd);
 
-      g_debug ("Operation %s:%u: Searching %u items from offset %u",
-	       grl_metadata_source_get_name (GRL_METADATA_SOURCE (source)),
-	       id, rc->count, skip);
+      GRL_DEBUG ("Operation %s:%u: Searching %u items from offset %u",
+                 grl_metadata_source_get_name (GRL_METADATA_SOURCE (source)),
+                 id, rc->count, skip);
 
       /* Keep track of this operation and this source */
       msd->search_ids = g_list_prepend (msd->search_ids, GINT_TO_POINTER (id));
@@ -275,7 +276,7 @@ multiple_result_async_cb (GrlMediaSource *source,
 {
   GrlDataSync *ds = (GrlDataSync *) user_data;
 
-  g_debug ("multiple_result_async_cb");
+  GRL_DEBUG ("multiple_result_async_cb");
 
   if (error) {
     ds->error = g_error_copy (error);
@@ -307,7 +308,7 @@ multiple_search_cb (GrlMediaSource *source,
 		    gpointer user_data,
 		    const GError *error)
 {
-  g_debug ("multiple_search_cb");
+  GRL_DEBUG ("multiple_search_cb");
 
   struct MultipleSearchData *msd;
   gboolean emit;
@@ -316,9 +317,9 @@ multiple_search_cb (GrlMediaSource *source,
 
   msd = (struct MultipleSearchData *) user_data;
 
-  g_debug ("multiple:remaining == %u, source:remaining = %u (%s)",
-	   msd->remaining, remaining,
-	   grl_metadata_source_get_name (GRL_METADATA_SOURCE (source)));
+  GRL_DEBUG ("multiple:remaining == %u, source:remaining = %u (%s)",
+             msd->remaining, remaining,
+             grl_metadata_source_get_name (GRL_METADATA_SOURCE (source)));
 
   /* Check if operation is done, that is, if all the sources involved
      in the multiple operation have emitted remaining=0 */
@@ -326,14 +327,14 @@ multiple_search_cb (GrlMediaSource *source,
     msd->sources_done++;
     if (msd->sources_done == msd->sources_count) {
       operation_done = TRUE;
-      g_debug ("multiple operation chunk done");
+      GRL_DEBUG ("multiple operation chunk done");
     }
   }
 
   /* --- Cancellation management --- */
 
   if (msd->cancelled) {
-    g_debug ("operation is cancelled or already finished, skipping result!");
+    GRL_DEBUG ("operation is cancelled or already finished, skipping result!");
     if (media) {
       g_object_unref (media);
       media = NULL;
@@ -369,8 +370,8 @@ multiple_search_cb (GrlMediaSource *source,
     /* This source provided all requested results, if others did not
        we can use this to request more */
     msd->sources_more = g_list_prepend (msd->sources_more, source);
-    g_debug ("Source %s provided all requested results",
-	     grl_metadata_source_get_name (GRL_METADATA_SOURCE (source)));
+    GRL_DEBUG ("Source %s provided all requested results",
+               grl_metadata_source_get_name (GRL_METADATA_SOURCE (source)));
   }
 
   /* --- Manage NULL results --- */
@@ -379,7 +380,7 @@ multiple_search_cb (GrlMediaSource *source,
     /* A source emitted a NULL result to finish its search operation
        we don't want to relay this to the client (unless this is the
        last one in the multiple search) */
-    g_debug ("Skipping NULL result");
+    GRL_DEBUG ("Skipping NULL result");
     emit = FALSE;
   } else {
     emit = TRUE;
@@ -401,7 +402,7 @@ multiple_search_cb (GrlMediaSource *source,
   if (operation_done && msd->pending > 0 && msd->sources_more) {
     /* We did not get all the requested results and have sources
        that can still provide more */
-    g_debug ("Requesting next chunk");
+    GRL_DEBUG ("Requesting next chunk");
     chain_multiple_search_operation (msd);
     return;
   } else if (operation_done && msd->pending > 0) {
@@ -423,7 +424,7 @@ multiple_search_cb (GrlMediaSource *source,
   }
 
  operation_done:
-  g_debug ("Multiple operation finished (%u)", msd->search_id);
+  GRL_DEBUG ("Multiple operation finished (%u)", msd->search_id);
   g_hash_table_remove (pending_operations, GINT_TO_POINTER (msd->search_id));
 }
 
@@ -459,7 +460,7 @@ grl_multiple_search (const GList *sources,
   struct MultipleSearchData *msd;
   gboolean allocated_sources_list = FALSE;
 
-  g_debug ("grl_multiple_search");
+  GRL_DEBUG ("grl_multiple_search");
 
   g_return_val_if_fail (count > 0, 0);
   g_return_val_if_fail (text != NULL, 0);
@@ -523,13 +524,13 @@ grl_multiple_search (const GList *sources,
 void
 grl_multiple_cancel (guint search_id)
 {
-  g_debug ("grl_multiple_cancel");
+  GRL_DEBUG ("grl_multiple_cancel");
 
   struct MultipleSearchData *msd;
   GList *sources, *ids;
 
   if (!pending_operations) {
-    g_debug ("No pending operations. Skipping...");
+    GRL_DEBUG ("No pending operations. Skipping...");
     return;
   }
 
@@ -537,8 +538,8 @@ grl_multiple_cancel (guint search_id)
   msd = (struct MultipleSearchData *)
     g_hash_table_lookup (pending_operations, GINT_TO_POINTER (search_id));
   if (!msd) {
-    g_debug ("Tried to cancel invalid or already cancelled "\
-	     "multiple operation. Skipping...");
+    GRL_DEBUG ("Tried to cancel invalid or already cancelled multiple "
+               "operation. Skipping...");
     return;
   }
 
@@ -547,9 +548,9 @@ grl_multiple_cancel (guint search_id)
   sources = msd->sources;
   ids = msd->search_ids;
   while (sources) {
-    g_debug ("cancelling operation %s:%u",
-	     grl_metadata_source_get_name (GRL_METADATA_SOURCE (sources->data)),
-	     GPOINTER_TO_UINT (ids->data));
+    GRL_DEBUG ("cancelling operation %s:%u",
+               grl_metadata_source_get_name (GRL_METADATA_SOURCE (sources->data)),
+               GPOINTER_TO_UINT (ids->data));
     grl_media_source_cancel (GRL_MEDIA_SOURCE (sources->data),
                              GPOINTER_TO_INT (ids->data));
     sources = g_list_next (sources);
diff --git a/src/grl-plugin-registry.c b/src/grl-plugin-registry.c
index b450a60..7007cf9 100644
--- a/src/grl-plugin-registry.c
+++ b/src/grl-plugin-registry.c
@@ -39,13 +39,14 @@
 
 #include "grl-plugin-registry.h"
 #include "grl-media-plugin-priv.h"
+#include "grl-log.h"
 
 #include <string.h>
 #include <gmodule.h>
 #include <libxml/parser.h>
 
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "grl-plugin-registry"
+#define GRL_LOG_DOMAIN_DEFAULT  plugin_registry_log_domain
+GRL_LOG_DOMAIN(plugin_registry_log_domain);
 
 #define XML_ROOT_ELEMENT_NAME "plugin"
 
@@ -139,7 +140,7 @@ config_plugin_rank (GrlPluginRegistry *registry,
 		    const gchar *plugin_id,
 		    gint rank)
 {
-  g_debug ("Rank configuration, '%s:%d'", plugin_id, rank);
+  GRL_DEBUG ("Rank configuration, '%s:%d'", plugin_id, rank);
   g_hash_table_insert (registry->priv->ranks,
 		       (gchar *) plugin_id,
 		       GINT_TO_POINTER (rank));
@@ -154,7 +155,7 @@ set_plugin_rank (GrlPluginRegistry *registry, GrlPluginDescriptor *plugin)
   if (!plugin->info.rank) {
     plugin->info.rank = GRL_PLUGIN_RANK_DEFAULT;
   }
-  g_debug ("Plugin rank '%s' : %d", plugin->info.id, plugin->info.rank);
+  GRL_DEBUG ("Plugin rank '%s' : %d", plugin->info.id, plugin->info.rank);
 }
 
 static void
@@ -169,7 +170,7 @@ grl_plugin_registry_setup_ranks (GrlPluginRegistry *registry)
 
   ranks_env = g_getenv (GRL_PLUGIN_RANKS_VAR);
   if (!ranks_env) {
-    g_debug ("$%s is not set, using default ranks.", GRL_PLUGIN_RANKS_VAR);
+    GRL_DEBUG ("$%s is not set, using default ranks.", GRL_PLUGIN_RANKS_VAR);
     return;
   }
 
@@ -184,12 +185,12 @@ grl_plugin_registry_setup_ranks (GrlPluginRegistry *registry)
       gchar *plugin_rank = rank_info[1];
       gint rank = (gint) g_ascii_strtoll (plugin_rank, &tmp, 10);
       if (*tmp != '\0') {
-	g_warning ("Incorrect ranking definition: '%s'. Skipping...", *iter);
+	GRL_WARNING ("Incorrect ranking definition: '%s'. Skipping...", *iter);
       } else {
 	config_plugin_rank (registry, g_strdup (plugin_id), rank);
       }
     } else {
-      g_warning ("Incorrect ranking definition: '%s'. Skipping...", *iter);
+      GRL_WARNING ("Incorrect ranking definition: '%s'. Skipping...", *iter);
     }
     g_strfreev (rank_info);
     iter++;
@@ -234,15 +235,15 @@ get_info_from_plugin_xml (const gchar *xml_path)
 				   XML_PARSE_RECOVER | XML_PARSE_NOBLANKS |
 				   XML_PARSE_NOWARNING | XML_PARSE_NOERROR);
   if (!doc_ptr) {
-    g_warning ("Could not read XML file under the location: %s", xml_path);
+    GRL_WARNING ("Could not read XML file under the location: %s", xml_path);
     return NULL;
   }
 
   node = xmlDocGetRootElement (doc_ptr);
   if (!node || g_strcmp0 ((gchar *) node->name, XML_ROOT_ELEMENT_NAME)) {
-    g_warning ("%s did not have a %s root element.",
-	       xml_path,
-	       XML_ROOT_ELEMENT_NAME);
+    GRL_WARNING ("%s did not have a %s root element.",
+                 xml_path,
+                 XML_ROOT_ELEMENT_NAME);
     xmlFreeDoc (doc_ptr);
     return NULL;
   }
@@ -319,7 +320,7 @@ grl_plugin_registry_register_source (GrlPluginRegistry *registry,
   g_return_val_if_fail (GRL_IS_MEDIA_PLUGIN (source), FALSE);
 
   g_object_get (source, "source-id", &id, NULL);
-  g_debug ("New source available: '%s'", id);
+  GRL_DEBUG ("New source available: '%s'", id);
 
   /* Take ownership of the plugin */
   g_object_ref_sink (source);
@@ -353,14 +354,14 @@ grl_plugin_registry_unregister_source (GrlPluginRegistry *registry,
   g_return_if_fail (GRL_IS_MEDIA_PLUGIN (source));
 
   g_object_get (source, "source-id", &id, NULL);
-  g_debug ("Unregistering source '%s'", id);
+  GRL_DEBUG ("Unregistering source '%s'", id);
 
   if (g_hash_table_remove (registry->priv->sources, id)) {
-    g_debug ("source '%s' is no longer available", id);
+    GRL_DEBUG ("source '%s' is no longer available", id);
     g_signal_emit (registry, registry_signals[SIG_SOURCE_REMOVED], 0, source);
     g_object_unref (source);
   } else {
-    g_warning ("source '%s' not found", id);
+    GRL_WARNING ("source '%s' not found", id);
   }
 }
 
@@ -405,19 +406,19 @@ grl_plugin_registry_load (GrlPluginRegistry *registry, const gchar *path)
 
   module = g_module_open (path, G_MODULE_BIND_LAZY);
   if (!module) {
-    g_warning ("Failed to open module: '%s'", path);
+    GRL_WARNING ("Failed to open module: '%s'", path);
     return FALSE;
   }
 
   if (!g_module_symbol (module, "GRL_PLUGIN_DESCRIPTOR", (gpointer) &plugin)) {
-    g_warning ("Did not find plugin descriptor: '%s'", path);
+    GRL_WARNING ("Did not find plugin descriptor: '%s'", path);
     g_module_close (module);
     return FALSE;
   }
 
   if (!plugin->plugin_init ||
       !plugin->info.id) {
-    g_warning ("Plugin descriptor is not valid: '%s'", path);
+    GRL_WARNING ("Plugin descriptor is not valid: '%s'", path);
     g_module_close (module);
     return FALSE;
   }
@@ -442,12 +443,12 @@ grl_plugin_registry_load (GrlPluginRegistry *registry, const gchar *path)
 
   if (!plugin->plugin_init (registry, &plugin->info, plugin_configs)) {
     g_hash_table_remove (registry->priv->plugins, plugin->info.id);
-    g_warning ("Failed to initialize plugin: '%s'", path);
+    GRL_WARNING ("Failed to initialize plugin: '%s'", path);
     g_module_close (module);
     return FALSE;
   }
 
-  g_debug ("Loaded plugin '%s' from '%s'", plugin->info.id, path);
+  GRL_DEBUG ("Loaded plugin '%s' from '%s'", plugin->info.id, path);
 
   return TRUE;
 }
@@ -475,7 +476,7 @@ grl_plugin_registry_load_directory (GrlPluginRegistry *registry,
   dir = g_dir_open (path, 0, NULL);
 
   if (!dir) {
-    g_warning ("Could not open plugin directory: '%s'", path);
+    GRL_WARNING ("Could not open plugin directory: '%s'", path);
     return FALSE;
   }
 
@@ -639,11 +640,11 @@ grl_plugin_registry_unload (GrlPluginRegistry *registry,
 
   plugin = g_hash_table_lookup (registry->priv->plugins, plugin_id);
   if (!plugin) {
-    g_warning ("Could not deinit plugin '%s'. Plugin not found.", plugin_id);
+    GRL_WARNING ("Could not deinit plugin '%s'. Plugin not found.", plugin_id);
     return;
   }
 
-  g_debug ("Unloading plugin '%s'", plugin_id);
+  GRL_DEBUG ("Unloading plugin '%s'", plugin_id);
   if (plugin->plugin_deinit) {
     plugin->plugin_deinit ();
   }
@@ -661,8 +662,8 @@ grl_plugin_registry_register_metadata_key (GrlPluginRegistry *registry,
                                 g_param_spec_get_name (key),
                                 GRL_TYPE_MEDIA,
                                 FALSE)) {
-    g_warning ("metadata key '%s' already registered",
-               g_param_spec_get_name (key));
+    GRL_WARNING ("metadata key '%s' already registered",
+                 g_param_spec_get_name (key));
     return NULL;
   } else {
     g_param_spec_pool_insert (registry->priv->system_keys,
@@ -744,7 +745,7 @@ grl_plugin_registry_add_config (GrlPluginRegistry *registry,
 
   plugin_id = grl_config_get_plugin (config);
   if (!plugin_id) {
-    g_warning ("Plugin configuration missed plugin information, ignoring...");
+    GRL_WARNING ("Plugin configuration missed plugin information, ignoring...");
     return;
   }
   
diff --git a/src/tests/registry.c b/src/tests/registry.c
index 5c5d772..54ba499 100644
--- a/src/tests/registry.c
+++ b/src/tests/registry.c
@@ -19,7 +19,6 @@
  */
 
 #undef G_DISABLE_ASSERT
-#undef G_LOG_DOMAIN
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -28,6 +27,9 @@
 
 #include <grilo.h>
 
+#define CHECK_MESSAGE(domain, error_message) \
+  (g_strcmp0 (log_domain, domain) == 0 && strstr (message, error_message))
+
 #if GLIB_CHECK_VERSION(2,22,0)
 static gboolean
 registry_load_error_handler (const gchar *log_domain,
@@ -35,11 +37,11 @@ registry_load_error_handler (const gchar *log_domain,
                              const gchar *message,
                              gpointer user_data)
 {
-  if (g_str_has_prefix (message, "Failed to initialize plugin") ||
-      g_str_has_prefix (message, "Configuration not provided") ||
-      g_strcmp0 (message, "Missing configuration") == 0 ||
-      g_str_has_prefix (message, "Could not open plugin directory") ||
-      g_str_has_prefix (message, "Could not read XML file")) {
+  if (CHECK_MESSAGE ("Grilo", "Failed to initialize plugin") ||
+      CHECK_MESSAGE ("Grilo", "Configuration not provided") ||
+      CHECK_MESSAGE ("Grilo", "Missing configuration") ||
+      CHECK_MESSAGE ("Grilo", "Could not open plugin directory") ||
+      CHECK_MESSAGE ("Grilo", "Could not read XML file")) {
     return FALSE;
   }
 
diff --git a/tools/grilo-test-ui/main.c b/tools/grilo-test-ui/main.c
index f3896ea..6c7e2ed 100644
--- a/tools/grilo-test-ui/main.c
+++ b/tools/grilo-test-ui/main.c
@@ -30,8 +30,8 @@
 
 #include "flickr-auth.h"
 
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "test-ui"
+#define GRL_LOG_DOMAIN_DEFAULT  test_ui_log_domain
+GRL_LOG_DOMAIN_STATIC(test_ui_log_domain);
 
 /* ----- Flickr Security tokens ---- */
 
@@ -262,7 +262,7 @@ load_icon (const gchar *icon_name)
   pixbuf = gtk_icon_theme_load_icon (theme, icon_name, 22, 22, &error);
 
   if (pixbuf == NULL) {
-    g_warning ("Failed to load icon %s: %s", icon_name,  error->message);
+    GRL_WARNING ("Failed to load icon %s: %s", icon_name,  error->message);
     g_error_free (error);
   }
 
@@ -452,7 +452,7 @@ metadata_cb (GrlMediaSource *source,
 			  METADATA_MODEL_NAME, GRL_METADATA_KEY_GET_NAME (i->data),
 			  METADATA_MODEL_VALUE, value,
 			  -1);
-      g_debug ("  %s: %s", GRL_METADATA_KEY_GET_NAME (i->data), value);
+      GRL_DEBUG ("  %s: %s", GRL_METADATA_KEY_GET_NAME (i->data), value);
       i = g_list_next (i);
     }
 
@@ -576,7 +576,7 @@ browse_cb (GrlMediaSource *source,
  browse_finished:
   g_free (state);
   operation_finished ();
-  g_debug ("**** browse finished (%d) ****", browse_id);
+  GRL_DEBUG ("**** browse finished (%d) ****", browse_id);
 }
 
 static void
@@ -727,7 +727,7 @@ show_btn_clicked_cb (GtkButton *btn, gpointer user_data)
   GAppInfo *app = NULL;
 
   if (ui_state->last_url) {
-    g_debug ("playing: %s", ui_state->last_url);
+    GRL_DEBUG ("playing: %s", ui_state->last_url);
     uri_list = g_list_append (uri_list, (gpointer) ui_state->last_url);
     if (GRL_IS_MEDIA_IMAGE (ui_state->cur_md_media)) {
       app = launchers->eog;
@@ -747,15 +747,15 @@ show_btn_clicked_cb (GtkButton *btn, gpointer user_data)
     g_list_free (uri_list);
 
     if (error) {
-      g_warning ("Cannot use '%s' to show '%s'; using default application",
-                 g_app_info_get_name (app),
-                 ui_state->last_url);
+      GRL_WARNING ("Cannot use '%s' to show '%s'; using default application",
+                   g_app_info_get_name (app),
+                   ui_state->last_url);
       g_error_free (error);
       error = NULL;
       g_app_info_launch_default_for_uri (ui_state->last_url, NULL, &error);
       if (error) {
-        g_warning ("Cannot use default application to show '%s'. "
-                   "Stopping playback", ui_state->last_url);
+        GRL_WARNING ("Cannot use default application to show '%s'. "
+                     "Stopping playback", ui_state->last_url);
         g_error_free (error);
       }
     }
@@ -793,9 +793,9 @@ store_cb (GrlMediaSource *source,
 	  const GError *error)
 {
   if (error) {
-    g_warning ("Error storing media: %s", error->message);
+    GRL_WARNING ("Error storing media: %s", error->message);
   } else {
-    g_debug ("Media stored");
+    GRL_DEBUG ("Media stored");
   }
   g_object_unref (media);
 }
@@ -910,9 +910,9 @@ remove_cb (GrlMediaSource *source,
 	   const GError *error)
 {
   if (error) {
-    g_warning ("Error removing media: %s", error->message);
+    GRL_WARNING ("Error removing media: %s", error->message);
   } else {
-    g_debug ("Media removed");
+    GRL_DEBUG ("Media removed");
   }
 
   remove_item_from_view (source, media);
@@ -1020,7 +1020,7 @@ search_cb (GrlMediaSource *source,
  search_finished:
   g_free (state);
   operation_finished ();
-  g_debug ("**** search finished (%d) ****", search_id);
+  GRL_DEBUG ("**** search finished (%d) ****", search_id);
 }
 
 static void
@@ -1230,7 +1230,7 @@ activate_ok_button (GtkLabel *label,
                     gchar *uri,
                     gpointer user_data)
 {
-  g_debug ("activate invoked");
+  GRL_DEBUG ("activate invoked");
   gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (label)),
                 uri,
                 GDK_CURRENT_TIME,
@@ -1252,7 +1252,7 @@ authorize_flickr (void)
 
   gchar *frob = flickr_get_frob (FLICKR_KEY, FLICKR_SECRET);
   if (!frob) {
-    g_warning ("Unable to obtain a Flickr's frob");
+    GRL_WARNING ("Unable to obtain a Flickr's frob");
     return NULL;
   }
 
@@ -1620,7 +1620,7 @@ show_plugins ()
     GdkPixbuf *icon;
     icon = load_icon (GTK_STOCK_DIRECTORY);
     name = grl_metadata_source_get_name (GRL_METADATA_SOURCE (sources[i]));
-    g_debug ("Loaded source: '%s'", name);
+    GRL_DEBUG ("Loaded source: '%s'", name);
     gtk_list_store_append (GTK_LIST_STORE (view->browser_model), &iter);
     gtk_list_store_set (GTK_LIST_STORE (view->browser_model),
 			&iter,
@@ -1674,15 +1674,15 @@ source_added_cb (GrlPluginRegistry *registry,
 		 GrlMediaPlugin *source,
 		 gpointer user_data)
 {
-  g_debug ("Detected new source available: '%s'",
+  GRL_DEBUG ("Detected new source available: '%s'",
 	   grl_metadata_source_get_name (GRL_METADATA_SOURCE (source)));
 
-  g_debug ("\tPlugin's name: %s", grl_media_plugin_get_name (GRL_MEDIA_PLUGIN (source)));
-  g_debug ("\tPlugin's description: %s", grl_media_plugin_get_description (GRL_MEDIA_PLUGIN (source)));
-  g_debug ("\tPlugin's author: %s", grl_media_plugin_get_author (GRL_MEDIA_PLUGIN (source)));
-  g_debug ("\tPlugin's license: %s", grl_media_plugin_get_license (GRL_MEDIA_PLUGIN (source)));
-  g_debug ("\tPlugin's version: %s", grl_media_plugin_get_version (GRL_MEDIA_PLUGIN (source)));
-  g_debug ("\tPlugin's web site: %s", grl_media_plugin_get_site (GRL_MEDIA_PLUGIN (source)));
+  GRL_DEBUG ("\tPlugin's name: %s", grl_media_plugin_get_name (GRL_MEDIA_PLUGIN (source)));
+  GRL_DEBUG ("\tPlugin's description: %s", grl_media_plugin_get_description (GRL_MEDIA_PLUGIN (source)));
+  GRL_DEBUG ("\tPlugin's author: %s", grl_media_plugin_get_author (GRL_MEDIA_PLUGIN (source)));
+  GRL_DEBUG ("\tPlugin's license: %s", grl_media_plugin_get_license (GRL_MEDIA_PLUGIN (source)));
+  GRL_DEBUG ("\tPlugin's version: %s", grl_media_plugin_get_version (GRL_MEDIA_PLUGIN (source)));
+  GRL_DEBUG ("\tPlugin's web site: %s", grl_media_plugin_get_site (GRL_MEDIA_PLUGIN (source)));
 
   /* If showing the plugin list, refresh it */
   if (!ui_state->cur_source && !ui_state->cur_container) {
@@ -1699,8 +1699,8 @@ source_removed_cb (GrlPluginRegistry *registry,
 		   GrlMediaPlugin *source,
 		   gpointer user_data)
 {
-  g_debug ("Source '%s' is gone",
-	   grl_metadata_source_get_name (GRL_METADATA_SOURCE (source)));
+  GRL_DEBUG ("Source '%s' is gone",
+             grl_metadata_source_get_name (GRL_METADATA_SOURCE (source)));
 
   if (!ui_state->cur_source && !ui_state->cur_container) {
     /* If showing the plugin list, refresh it */
@@ -1708,7 +1708,7 @@ source_removed_cb (GrlPluginRegistry *registry,
   } else if ((gpointer)ui_state->cur_source == user_data ) {
     /* If we were browsing that source, cancel operation and  go back to
        plugin list view */
-    g_debug ("Currently browsing the removed source: resetting UI.");
+    GRL_DEBUG ("Currently browsing the removed source: resetting UI.");
     reset_ui ();
   }
 
@@ -1770,6 +1770,7 @@ main (int argc, gchar *argv[])
 {
   gtk_init (&argc, &argv);
   grl_init (&argc, &argv);
+  GRL_LOG_DOMAIN_INIT (test_ui_log_domain, "test-ui");
   grl_log_init ("*:*");
   launchers_setup ();
   ui_setup ();
-- 
1.7.1



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