[folks] Add new API for setting debugging levels.
- From: Travis Reitter <treitter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Add new API for setting debugging levels.
- Date: Thu, 6 Jan 2011 23:45:32 +0000 (UTC)
commit 74966cd86b4b213eaad81bcb5c8d5a2738ba1f8c
Author: Travis Reitter <travis reitter collabora co uk>
Date: Tue Jan 4 10:54:01 2011 -0800
Add new API for setting debugging levels.
Helps bgo#638609 - libfolks hard-codes backend names for debugging
folks/backend-store.vala | 9 ++++++-
folks/debug.vala | 49 +++++++++++++++++++++++++++++----------------
2 files changed, 38 insertions(+), 20 deletions(-)
---
diff --git a/folks/backend-store.vala b/folks/backend-store.vala
index d264685..89dd778 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.
@@ -118,10 +119,12 @@ public class Folks.BackendStore : Object {
private BackendStore ()
{
- var debug = Debug.dup ();
+ this._debug = Debug.dup ();
/* Treat this as a library init function */
- debug._set_flags (Environment.get_variable ("FOLKS_DEBUG"));
+ this._debug._set_flags (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);
@@ -308,6 +311,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 583bb3f..396dff3 100644
--- a/folks/debug.vala
+++ b/folks/debug.vala
@@ -31,32 +31,45 @@ internal class Folks.Debug : Object
}
private static weak Debug _instance;
+ private HashSet<string> _domains;
+ private bool _all = false;
internal void _set_flags (string? debug_flags)
{
- /* FIXME: we obviously shouldn't be hard-coding these. See bgo#638609 */
- GLib.DebugKey keys[3] =
+ this._all = false;
+ this._domains = new HashSet<string> (str_hash, str_equal);
+
+ if (debug_flags == null || debug_flags == "")
+ return;
+
+ var domains_split = debug_flags.split (",");
+ foreach (var domain in domains_split)
{
- DebugKey () { key = "Core", value = Domains.CORE },
- DebugKey () { key = "TelepathyBackend",
- value = Domains.TELEPATHY_BACKEND },
- DebugKey () { key = "KeyFileBackend",
- value = Domains.KEY_FILE_BACKEND }
- };
+ var domain_lower = domain.down ();
- var flags = GLib.parse_debug_string (debug_flags, keys);
+ if (GLib.strcmp (domain_lower, "all") == 0)
+ this._all = true;
+ else
+ this._domains.add (domain_lower);
+ }
+ }
- foreach (unowned DebugKey key in keys)
+ /* 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 ()))
{
- if ((flags & key.value) == 0)
- {
- /* 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) => {});
- }
+ /* 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 ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]