diff --git a/backends/key-file/Makefile.am b/backends/key-file/Makefile.am
index 22c5ed4..ab5dab8 100644
--- a/backends/key-file/Makefile.am
+++ b/backends/key-file/Makefile.am
@@ -2,7 +2,7 @@ AM_CPPFLAGS = \
 	-I$(top_srcdir)/folks \
 	-include $(CONFIG_HEADER) \
 	-DPACKAGE_DATADIR=\"$(pkgdatadir)\" \
-	-DG_LOG_DOMAIN=\"KeyFileBackend\" \
+	-DG_LOG_DOMAIN=\"key-file\" \
 	$(NULL)
 
 backenddir = $(BACKEND_DIR)/key-file
diff --git a/backends/key-file/kf-backend.vala b/backends/key-file/kf-backend.vala
index a2e720d..e3c554d 100644
--- a/backends/key-file/kf-backend.vala
+++ b/backends/key-file/kf-backend.vala
@@ -22,6 +22,8 @@ using GLib;
 using Folks;
 using Folks.Backends.Kf;
 
+extern const string G_LOG_DOMAIN;
+
 /**
  * A backend which loads {@link Persona}s from a simple key file in
  * (XDG_DATA_HOME/folks/) and presents them through a single
@@ -49,7 +51,7 @@ public class Folks.Backends.Kf.Backend : Folks.Backend
   /**
    * {@inheritDoc}
    */
-  public override string name { get { return "key-file"; } }
+  public override string name { get { return G_LOG_DOMAIN; } }
 
   /**
    * {@inheritDoc}
diff --git a/backends/key-file/kf-persona-store.vala b/backends/key-file/kf-persona-store.vala
index 16b3c79..c141c99 100644
--- a/backends/key-file/kf-persona-store.vala
+++ b/backends/key-file/kf-persona-store.vala
@@ -41,7 +41,7 @@ public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
   /**
    * {@inheritDoc}
    */
-  public override string type_id { get { return "key-file"; } }
+  public override string type_id { get { return G_LOG_DOMAIN; } }
 
   /**
    * Whether this PersonaStore can add {@link Folks.Persona}s.
diff --git a/backends/telepathy/Makefile.am b/backends/telepathy/Makefile.am
index 385e833..c3f0793 100644
--- a/backends/telepathy/Makefile.am
+++ b/backends/telepathy/Makefile.am
@@ -5,7 +5,7 @@ AM_CPPFLAGS = \
 	-I$(top_srcdir)/backends/telepathy/lib \
 	-include $(CONFIG_HEADER) \
 	-DPACKAGE_DATADIR=\"$(pkgdatadir)\" \
-	-DG_LOG_DOMAIN=\"TelepathyBackend\" \
+	-DG_LOG_DOMAIN=\"telepathy\" \
 	$(NULL)
 
 VALAFLAGS += \
diff --git a/backends/telepathy/lib/Makefile.am b/backends/telepathy/lib/Makefile.am
index 9f86fb3..8db28c8 100644
--- a/backends/telepathy/lib/Makefile.am
+++ b/backends/telepathy/lib/Makefile.am
@@ -2,7 +2,7 @@ AM_CPPFLAGS = \
 	-I$(top_srcdir)/folks \
 	-include $(CONFIG_HEADER) \
 	-DPACKAGE_DATADIR=\"$(pkgdatadir)\" \
-	-DG_LOG_DOMAIN=\"TelepathyBackend\" \
+	-DG_LOG_DOMAIN=\"telepathy\" \
 	$(NULL)
 
 VAPIGENFLAGS += \
diff --git a/backends/telepathy/lib/tpf-persona-store.vala b/backends/telepathy/lib/tpf-persona-store.vala
index 116e5d8..43cc747 100644
--- a/backends/telepathy/lib/tpf-persona-store.vala
+++ b/backends/telepathy/lib/tpf-persona-store.vala
@@ -24,6 +24,8 @@ using Gee;
 using TelepathyGLib;
 using Folks;
 
+extern const string G_LOG_DOMAIN;
+
 /**
  * A persona store which is associated with a single Telepathy account. It will
  * create {@link Persona}s for each of the contacts in the published, stored or
@@ -88,7 +90,6 @@ public class Tpf.PersonaStore : Folks.PersonaStore
       GLib.List<Persona>? added, GLib.List<Persona>? removed);
   internal signal void group_removed (string group, GLib.Error? error);
 
-
   /**
    * The Telepathy account this store is based upon.
    */
@@ -101,7 +102,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
    *
    * See {@link Folks.PersonaStore.type_id}.
    */
-  public override string type_id { get { return "telepathy"; } }
+  public override string type_id { get { return G_LOG_DOMAIN; } }
 
   /**
    * Whether this PersonaStore can add {@link Folks.Persona}s.
diff --git a/backends/telepathy/tp-backend.vala b/backends/telepathy/tp-backend.vala
index 3595b23..51f2c1a 100644
--- a/backends/telepathy/tp-backend.vala
+++ b/backends/telepathy/tp-backend.vala
@@ -23,6 +23,8 @@ using TelepathyGLib;
 using Folks;
 using Folks.Backends.Tp;
 
+extern const string G_LOG_DOMAIN;
+
 /**
  * A backend which connects to the Telepathy accounts service and creates a
  * {@link PersonaStore} for each valid account known to Telepathy.
@@ -36,7 +38,7 @@ public class Folks.Backends.Tp.Backend : Folks.Backend
   /**
    * {@inheritDoc}
    */
-  public override string name { get { return "telepathy"; } }
+  public override string name { get { return G_LOG_DOMAIN; } }
 
   /**
    * {@inheritDoc}
diff --git a/folks/Makefile.am b/folks/Makefile.am
index f5be30d..c18f227 100644
--- a/folks/Makefile.am
+++ b/folks/Makefile.am
@@ -5,7 +5,7 @@ AM_CPPFLAGS = \
 	-DPACKAGE_DATADIR=\"$(pkgdatadir)\" \
 	-DDATA_DIR=\"$(shareddir)\" \
 	-DBACKEND_DIR=\"$(BACKEND_DIR)\" \
-	-DG_LOG_DOMAIN=\"Core\" \
+	-DG_LOG_DOMAIN=\"folks\" \
 	$(NULL)
 
 lib_LTLIBRARIES = libfolks.la
diff --git a/folks/backend-store.vala b/folks/backend-store.vala
index e96f27b..cb40821 100644
--- a/folks/backend-store.vala
+++ b/folks/backend-store.vala
@@ -47,6 +47,7 @@ public class Folks.BackendStore : Object {
   private HashMap<string,unowned Module> modules;
   private static weak BackendStore instance;
   private bool _is_prepared = false;
+  private Debug _debug;
 
   /**
    * Emitted when a backend has been added to the BackendStore.
@@ -119,7 +120,10 @@ public class Folks.BackendStore : Object {
   private BackendStore ()
     {
       /* Treat this as a library init function */
-      Debug._set_flags (Environment.get_variable ("FOLKS_DEBUG"));
+      this._debug = Debug.dup (Environment.get_variable ("FOLKS_DEBUG"));
+
+      /* register the core debug messages */
+      this._debug._register_domain ("folks");
 
       this.modules = new HashMap<string,unowned Module> (str_hash, str_equal);
       this._backend_hash = new HashMap<string,Backend> (str_hash, str_equal);
@@ -306,6 +310,8 @@ public class Folks.BackendStore : Object {
           this._prepared_backends.unset (backend_existing.name);
         }
 
+      this._debug._register_domain (backend.name);
+
       this._backend_hash.set (backend.name, backend);
     }
 
diff --git a/folks/debug.vala b/folks/debug.vala
index 2ba27d6..5e11cea 100644
--- a/folks/debug.vala
+++ b/folks/debug.vala
@@ -19,8 +19,9 @@
  */
 
 using GLib;
+using Gee;
 
-namespace Folks.Debug
+internal class Folks.Debug : Object
 {
   private enum Domains {
     /* Zero is used for "no debug spew" */
@@ -29,30 +30,62 @@ namespace Folks.Debug
     KEY_FILE_BACKEND = 1 << 2
   }
 
-  internal static void _set_flags (string? debug_flags)
+  private static weak Debug _instance;
+  private HashSet<string> _domains;
+  private bool _all = false;
+
+  /* turn off debug output for the given domain unless it was in the FOLKS_DEBUG
+   * environment variable (or 'all' was set) */
+  internal void _register_domain (string domain)
+    {
+      if (this._all || this._domains.contains (domain.down ()))
+        {
+          /* FIXME: shouldn't need to cast. See bgo#638682 */
+          Log.set_handler (domain, LogLevelFlags.LEVEL_MASK,
+              (LogFunc) Log.default_handler);
+          return;
+        }
+
+      /* Install a log handler which will blackhole the log message.
+       * Other log messages will be printed out by the default log handler. */
+      Log.set_handler (domain, LogLevelFlags.LEVEL_DEBUG,
+          (domain_arg, flags, message) => {});
+    }
+
+  internal static Debug dup (string? debug_flags)
     {
-      /* FIXME: we obviously shouldn't be hard-coding these. See bgo#638609 */
-      GLib.DebugKey keys[3] =
+      var retval = _instance;
+
+      if (retval == null)
         {
-          DebugKey () { key = "Core", value = Domains.CORE },
-          DebugKey () { key = "TelepathyBackend",
-              value = Domains.TELEPATHY_BACKEND },
-          DebugKey () { key = "KeyFileBackend",
-              value = Domains.KEY_FILE_BACKEND }
-        };
+          /* use an intermediate variable to force a strong reference */
+          retval = new Debug ();
+          _instance = retval;
+        }
 
-      var flags = GLib.parse_debug_string (debug_flags, keys);
+      retval._all = false;
+      retval._domains = new HashSet<string> (str_hash, str_equal);
 
-      foreach (unowned DebugKey key in keys)
+      if (debug_flags != null && debug_flags != "")
         {
-          if ((flags & key.value) == 0)
+          var domains_split = debug_flags.split (",");
+          foreach (var domain in domains_split)
             {
-              /* Install a log handler which will blackhole the log message.
-               * Other log messages will be printed out by the default log
-               * handler. */
-              Log.set_handler (key.key, LogLevelFlags.LEVEL_DEBUG,
-                  (domain, flags, message) => {});
+              var domain_lower = domain.down ();
+
+              if (GLib.strcmp (domain_lower, "all") == 0)
+                retval._all = true;
+              else
+                retval._domains.add (domain_lower);
             }
         }
+
+      return retval;
+    }
+
+  ~Debug ()
+    {
+      /* manually clear the singleton _instance */
+      _instance = null;
     }
 }
