summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2011-02-24 17:48:09 -0500
committerMatthias Clasen <mclasen@redhat.com>2011-02-24 17:48:09 -0500
commite3c58ec8361fdabd01947803688ccc519475dab0 (patch)
tree4fa630a4577f1b086002368dc1d35781de585798 /src
parentb475009b67560759a058cfa083ba72c2a61cbaf2 (diff)
Add a --debug commandline option
Having this makes g_debug() a lot more useful.
Diffstat (limited to 'src')
-rw-r--r--src/main.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 6953de4..ad00910 100644
--- a/src/main.c
+++ b/src/main.c
@@ -111,6 +111,21 @@ acquire_name_on_proxy (DBusGProxy *system_bus_proxy,
return ret;
}
+static gboolean debug;
+
+static void
+log_handler (const gchar *domain,
+ GLogLevelFlags level,
+ const gchar *message,
+ gpointer data)
+{
+ /* filter out DEBUG messages if debug isn't set */
+ if ((level & G_LOG_LEVEL_MASK) == G_LOG_LEVEL_DEBUG && !debug)
+ return;
+
+ g_log_default_handler (domain, level, message, data);
+}
+
int
main (int argc, char *argv[])
{
@@ -125,6 +140,8 @@ main (int argc, char *argv[])
static GOptionEntry entries[] = {
{ "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Output version information and exit"), NULL },
{ "replace", 0, 0, G_OPTION_ARG_NONE, &replace, N_("Replace existing instance"), NULL },
+ { "debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Enable debugging code"), NULL },
+
{ NULL }
};
@@ -159,6 +176,8 @@ main (int argc, char *argv[])
goto out;
}
+ g_log_set_default_handler (log_handler, NULL);
+
bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
if (bus == NULL) {
g_warning ("Could not connect to system bus: %s", error->message);