Updated Bengali translation, a month and a half after it was submitted. Fixes #12141.
[pidgin-git.git] / libpurple / debug.c
blobca17f62bde95ee25a3f698f85921c89318e91be8
1 /**
2 * @file debug.c Debug API
3 * @ingroup core
4 */
6 /* purple
8 * Purple is the legal property of its developers, whose names are too numerous
9 * to list here. Please refer to the COPYRIGHT file distributed with this
10 * source distribution.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 #include "internal.h"
27 #include "debug.h"
28 #include "prefs.h"
29 #include "util.h"
31 static PurpleDebugUiOps *debug_ui_ops = NULL;
34 * This determines whether debug info should be written to the
35 * console or not.
37 * It doesn't make sense to make this a normal Purple preference
38 * because it's a command line option. This will always be FALSE,
39 * unless the user explicitly started the UI with the -d flag.
40 * It doesn't matter what this value was the last time Purple was
41 * started, so it doesn't make sense to save it in prefs.
43 static gboolean debug_enabled = FALSE;
46 * These determine whether verbose or unsafe debugging are desired. I
47 * don't want to make these purple preferences because their values should
48 * not be remembered across instances of the UI.
50 static gboolean debug_verbose = FALSE;
51 static gboolean debug_unsafe = FALSE;
53 static void
54 purple_debug_vargs(PurpleDebugLevel level, const char *category,
55 const char *format, va_list args)
57 PurpleDebugUiOps *ops;
58 char *arg_s = NULL;
60 g_return_if_fail(level != PURPLE_DEBUG_ALL);
61 g_return_if_fail(format != NULL);
63 ops = purple_debug_get_ui_ops();
65 if (!debug_enabled && ((ops == NULL) || (ops->print == NULL) ||
66 (ops->is_enabled && !ops->is_enabled(level, category))))
67 return;
69 arg_s = g_strdup_vprintf(format, args);
71 if (debug_enabled) {
72 gchar *ts_s;
73 const char *mdate;
74 time_t mtime = time(NULL);
77 mdate = purple_utf8_strftime("%H:%M:%S", localtime(&mtime));
78 ts_s = g_strdup_printf("(%s) ", mdate);
80 if (category == NULL)
81 g_print("%s%s", ts_s, arg_s);
82 else
83 g_print("%s%s: %s", ts_s, category, arg_s);
85 g_free(ts_s);
88 if (ops != NULL && ops->print != NULL)
89 ops->print(level, category, arg_s);
91 g_free(arg_s);
94 void
95 purple_debug(PurpleDebugLevel level, const char *category,
96 const char *format, ...)
98 va_list args;
100 g_return_if_fail(level != PURPLE_DEBUG_ALL);
101 g_return_if_fail(format != NULL);
103 va_start(args, format);
104 purple_debug_vargs(level, category, format, args);
105 va_end(args);
108 void
109 purple_debug_misc(const char *category, const char *format, ...)
111 va_list args;
113 g_return_if_fail(format != NULL);
115 va_start(args, format);
116 purple_debug_vargs(PURPLE_DEBUG_MISC, category, format, args);
117 va_end(args);
120 void
121 purple_debug_info(const char *category, const char *format, ...)
123 va_list args;
125 g_return_if_fail(format != NULL);
127 va_start(args, format);
128 purple_debug_vargs(PURPLE_DEBUG_INFO, category, format, args);
129 va_end(args);
132 void
133 purple_debug_warning(const char *category, const char *format, ...)
135 va_list args;
137 g_return_if_fail(format != NULL);
139 va_start(args, format);
140 purple_debug_vargs(PURPLE_DEBUG_WARNING, category, format, args);
141 va_end(args);
144 void
145 purple_debug_error(const char *category, const char *format, ...)
147 va_list args;
149 g_return_if_fail(format != NULL);
151 va_start(args, format);
152 purple_debug_vargs(PURPLE_DEBUG_ERROR, category, format, args);
153 va_end(args);
156 void
157 purple_debug_fatal(const char *category, const char *format, ...)
159 va_list args;
161 g_return_if_fail(format != NULL);
163 va_start(args, format);
164 purple_debug_vargs(PURPLE_DEBUG_FATAL, category, format, args);
165 va_end(args);
168 void
169 purple_debug_set_enabled(gboolean enabled)
171 debug_enabled = enabled;
174 gboolean
175 purple_debug_is_enabled()
177 return debug_enabled;
180 void
181 purple_debug_set_ui_ops(PurpleDebugUiOps *ops)
183 debug_ui_ops = ops;
186 gboolean
187 purple_debug_is_verbose()
189 return debug_verbose;
192 void
193 purple_debug_set_verbose(gboolean verbose)
195 debug_verbose = verbose;
198 gboolean
199 purple_debug_is_unsafe()
201 return debug_unsafe;
204 void
205 purple_debug_set_unsafe(gboolean unsafe)
207 debug_unsafe = unsafe;
210 PurpleDebugUiOps *
211 purple_debug_get_ui_ops(void)
213 return debug_ui_ops;
216 void
217 purple_debug_init(void)
219 /* Read environment variables once per init */
220 if(g_getenv("PURPLE_UNSAFE_DEBUG"))
221 purple_debug_set_unsafe(TRUE);
223 if(g_getenv("PURPLE_VERBOSE_DEBUG"))
224 purple_debug_set_verbose(TRUE);
226 purple_prefs_add_none("/purple/debug");
229 * This pref is obsolete and no longer referenced anywhere. It only
230 * survives here because it would be an API break if we removed it.
231 * Remove this when we get to 3.0.0 :)
233 purple_prefs_add_bool("/purple/debug/timestamps", TRUE);