From bea343d2874cca4d553ae73dc7603a4c0aabc37b Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 29 Jun 2010 15:18:54 +0100 Subject: [PATCH] Add debug flags support Debug flags for libfolks, controlling which debug domains spew messages, can be specified using the FOLKS_DEBUG environment variable, with a GLib-style debug flags string. The two initial debug domains are: * Core: everything in the folks directory * TelepathyBackend: everything in the backends/telepathy directory --- backends/telepathy/Makefile.am | 1 + folks/Makefile.am | 2 ++ folks/debug.vala | 54 ++++++++++++++++++++++++++++++++++++++++ folks/individual-aggregator.vala | 2 ++ 4 files changed, 59 insertions(+) create mode 100644 folks/debug.vala diff --git a/backends/telepathy/Makefile.am b/backends/telepathy/Makefile.am index f5d7036..a7882fd 100644 --- a/backends/telepathy/Makefile.am +++ b/backends/telepathy/Makefile.am @@ -2,6 +2,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/folks \ -include $(CONFIG_HEADER) \ -DPACKAGE_DATADIR=\"$(pkgdatadir)\" \ + -DG_LOG_DOMAIN=\"TelepathyBackend\" \ $(NULL) VALAFLAGS += $(TP_VALA_VALAFLAGS) diff --git a/folks/Makefile.am b/folks/Makefile.am index c3d025e..f9d3b83 100644 --- a/folks/Makefile.am +++ b/folks/Makefile.am @@ -6,6 +6,7 @@ AM_CPPFLAGS = \ -DPACKAGE_DATADIR=\"$(pkgdatadir)\" \ -DDATA_DIR=\"$(shareddir)\" \ -DBACKEND_DIR=\"$(backenddir)\" \ + -DG_LOG_DOMAIN=\"Core\" \ $(NULL) lib_LTLIBRARIES = libfolks.la @@ -23,6 +24,7 @@ folks_valasources = \ persona.vala \ persona-store.vala \ presence.vala \ + debug.vala \ $(NULL) libfolks_la_SOURCES = $(folks_valasources:.vala=.c) diff --git a/folks/debug.vala b/folks/debug.vala new file mode 100644 index 0000000..f56de98 --- /dev/null +++ b/folks/debug.vala @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2010 Collabora Ltd. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + * + * Authors: + * Philip Withnall + */ + +using GLib; + +namespace Folks.Debug +{ + private enum Domains { + /* Zero is used for "no debug spew" */ + CORE = 1 << 0, + TELEPATHY_BACKEND = 1 << 1 + } + + internal static void set_flags (string? debug_flags) + { + GLib.DebugKey keys[2] = + { + DebugKey () { key = "Core", value = Domains.CORE }, + DebugKey () { key = "TelepathyBackend", + value = Domains.TELEPATHY_BACKEND } + }; + + uint flags = GLib.parse_debug_string (debug_flags, keys); + + foreach (unowned DebugKey key in keys) + { + 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) => {}); + } + } + } +} diff --git a/folks/individual-aggregator.vala b/folks/individual-aggregator.vala index 1e9ab6e..5d602a3 100644 --- a/folks/individual-aggregator.vala +++ b/folks/individual-aggregator.vala @@ -104,6 +104,8 @@ public class Folks.IndividualAggregator : Object this.backends = new HashSet (); + Debug.set_flags (Environment.get_variable ("FOLKS_DEBUG")); + this.backend_store = new BackendStore (); this.backend_store.backend_available.connect (this.backend_available_cb); } -- 2.7.4