]> git.0d.be Git - empathy.git/blob - libempathy/gossip-debug.c
[darcs-to-svn @ Adding salut profile]
[empathy.git] / libempathy / gossip-debug.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2006-2007 Imendio AB
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  * Authors: Richard Hult <richard@imendio.com>
21  */
22
23 #include "config.h"
24
25 #include <stdarg.h>
26 #include <string.h>
27
28 #include <glib.h>
29 #include <glib/gprintf.h>
30
31 /* Set EMPATHY_DEBUG to a colon/comma/space separated list of domains, or "all"
32  * to get all debug output.
33  */
34
35 #include "gossip-debug.h"
36
37 static gchar    **debug_strv;
38 static gboolean   all_domains = FALSE;
39
40 static void
41 debug_init (void)
42 {
43         static gboolean inited = FALSE;
44
45         if (!inited) {
46                 const gchar *env;
47                 gint         i;
48
49                 env = g_getenv ("EMPATHY_DEBUG");
50
51                 if (env) {
52                         debug_strv = g_strsplit_set (env, ":, ", 0);
53                 } else {
54                         debug_strv = NULL;
55                 }
56
57                 for (i = 0; debug_strv && debug_strv[i]; i++) {
58                         if (strcmp ("all", debug_strv[i]) == 0) {
59                                 all_domains = TRUE;
60                         }
61                 }
62
63                 inited = TRUE;
64         }
65 }
66
67 void
68 gossip_debug_impl (const gchar *domain, const gchar *msg, ...)
69 {
70         gint i;
71
72         g_return_if_fail (domain != NULL);
73         g_return_if_fail (msg != NULL);
74
75         debug_init ();
76
77         for (i = 0; debug_strv && debug_strv[i]; i++) {
78                 if (all_domains || strcmp (domain, debug_strv[i]) == 0) {
79                         va_list args;
80
81                         g_print ("%s: ", domain);
82
83                         va_start (args, msg);
84                         g_vprintf (msg, args);
85                         va_end (args);
86
87                         g_print ("\n");
88                         break;
89                 }
90         }
91 }
92