telepathy: add automatic authentication scheme option
[siplcs.git] / src / telepathy / telepathy-debug.c
blob19f7bcb9e8f0bb30d9278710eda724c533e5a95e
1 /**
2 * @file telepathy-debug.c
4 * pidgin-sipe
6 * Copyright (C) 2012-2014 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 ******************************************************************************
24 * How to collect debugging information
26 * Run the connection manager from the command line like this:
28 * $ G_MESSAGES_DEBUG="all" SIPE_PERSIST=1 \
29 * SIPE_DEBUG=[space separated keyword list \
30 * [SIPE_TIMING=1] [SIPE_LOGFILE="..."] \
31 * telepathy-sipe
33 * G_MESSAGES_DEBUG=all: make debug & informational messages visible
35 * SIPE_PERSISTS=1 : keep the CM running permanently,
36 * [otherwise the one installed in the system will
37 * be started automatically by D-Bus when needed]
39 * SIPE_DEBUG=... :
40 * all - enable all sipe & telepathy-glib messages
41 * sipe - enable only sipe messages
42 * "sipe ..." - enable sipe and some telepathy-glib messages
44 * SIPE_TIMING=1 : enable time stamps
45 * [recommeded for any usable log file]
47 * SIPE_LOGFILE="..." : redirect output to this file
48 * [prepend file name with "+" to enable append mode]
50 ******************************************************************************
53 #include <stdarg.h>
55 #include <glib.h>
56 #include <telepathy-glib/debug-sender.h>
57 #include <telepathy-glib/telepathy-glib.h>
59 #include "sipe-backend.h"
61 #include "telepathy-private.h"
63 #define SIPE_TELEPATHY_DEBUG 1
65 static TpDebugSender *debug;
66 static guint flags = 0;
68 void sipe_telepathy_debug_init(void)
70 static const GDebugKey const keys[] = {
71 /* This simulates pidgin's --debug flag, i.e. we only see
72 * output from SIPE if this is set.
74 * @TODO: we could make this more finely grained, i.e.
75 * which levels should be visible
77 { "sipe", SIPE_TELEPATHY_DEBUG },
79 const gchar *env_flags = g_getenv("SIPE_DEBUG");
81 /* Telepathy debugger */
82 debug = tp_debug_sender_dup();
84 /* divert g_log_default_handler() output to a logfile */
85 tp_debug_divert_messages(g_getenv("SIPE_LOGFILE"));
87 /* sipe & telepathy-glib debugging flags */
88 if (env_flags) flags |= g_parse_debug_string(env_flags, keys, 1);
89 tp_debug_set_flags(env_flags);
91 /* add time stamps to debug output */
92 if (g_getenv("SIPE_TIMING"))
93 g_log_set_default_handler(tp_debug_timestamped_log_handler, NULL);
95 /* enable test mode */
96 if (g_getenv("SIPE_PERSIST"))
97 tp_debug_set_persistent(TRUE);
100 void sipe_telepathy_debug_finalize(void)
102 g_object_unref(debug);
105 static const GLogLevelFlags debug_level_mapping[] = {
106 G_LOG_LEVEL_DEBUG, /* SIPE_DEBUG_LEVEL_INFO */
107 G_LOG_LEVEL_WARNING, /* SIPE_DEBUG_LEVEL_WARNING */
108 G_LOG_LEVEL_CRITICAL, /* SIPE_DEBUG_LEVEL_ERROR */
111 void sipe_backend_debug_literal(sipe_debug_level level,
112 const gchar *msg)
114 if (flags & SIPE_TELEPATHY_DEBUG) {
115 GLogLevelFlags g_level = debug_level_mapping[level];
116 g_log(SIPE_TELEPATHY_DOMAIN, g_level, "%s", msg);
117 tp_debug_sender_add_message(debug, NULL,
118 SIPE_TELEPATHY_DOMAIN,
119 g_level,
120 msg);
124 void sipe_backend_debug(sipe_debug_level level,
125 const gchar *format,
126 ...)
128 va_list ap;
130 va_start(ap, format);
131 if (flags & SIPE_TELEPATHY_DEBUG) {
132 gchar *msg = g_strdup_vprintf(format, ap);
133 sipe_backend_debug_literal(level, msg);
134 g_free(msg);
136 va_end(ap);
139 gboolean sipe_backend_debug_enabled(void)
141 return(flags & SIPE_TELEPATHY_DEBUG);
145 Local Variables:
146 mode: c
147 c-file-style: "bsd"
148 indent-tabs-mode: t
149 tab-width: 8
150 End: