14192
|
1 /**
|
|
2 * @file debug.c Debug API
|
|
3 * @ingroup core
|
|
4 *
|
|
5 * gaim
|
|
6 *
|
|
7 * Gaim is the legal property of its developers, whose names are too numerous
|
|
8 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
9 * source distribution.
|
|
10 *
|
|
11 * This program is free software; you can redistribute it and/or modify
|
|
12 * it under the terms of the GNU General Public License as published by
|
|
13 * the Free Software Foundation; either version 2 of the License, or
|
|
14 * (at your option) any later version.
|
|
15 *
|
|
16 * This program is distributed in the hope that it will be useful,
|
|
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19 * GNU General Public License for more details.
|
|
20 *
|
|
21 * You should have received a copy of the GNU General Public License
|
|
22 * along with this program; if not, write to the Free Software
|
|
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
24 */
|
|
25 #include "debug.h"
|
|
26 #include "internal.h"
|
|
27 #include "prefs.h"
|
|
28 #include "util.h"
|
|
29
|
|
30 static GaimDebugUiOps *debug_ui_ops = NULL;
|
|
31
|
|
32 /*
|
|
33 * This determines whether debug info should be written to the
|
|
34 * console or not.
|
|
35 *
|
|
36 * It doesn't make sense to make this a normal Gaim preference
|
|
37 * because it's a command line option. This will always be FALSE,
|
|
38 * unless the user explicitly started Gaim with the -d flag.
|
|
39 * It doesn't matter what this value was the last time Gaim was
|
|
40 * started, so it doesn't make sense to save it in prefs.
|
|
41 */
|
|
42 static gboolean debug_enabled = FALSE;
|
|
43
|
|
44 static void
|
|
45 gaim_debug_vargs(GaimDebugLevel level, const char *category,
|
|
46 const char *format, va_list args)
|
|
47 {
|
|
48 GaimDebugUiOps *ops;
|
|
49 char *arg_s = NULL;
|
|
50
|
|
51 g_return_if_fail(level != GAIM_DEBUG_ALL);
|
|
52 g_return_if_fail(format != NULL);
|
|
53
|
|
54 ops = gaim_debug_get_ui_ops();
|
|
55
|
|
56 if (!debug_enabled && ((ops == NULL) || (ops->print == NULL)))
|
|
57 return;
|
|
58
|
|
59 arg_s = g_strdup_vprintf(format, args);
|
|
60
|
|
61 if (debug_enabled) {
|
|
62 gchar *ts_s;
|
|
63
|
|
64 if ((category != NULL) &&
|
|
65 (gaim_prefs_exists("/core/debug/timestamps")) &&
|
|
66 (gaim_prefs_get_bool("/core/debug/timestamps"))) {
|
|
67 const char *mdate;
|
|
68
|
|
69 time_t mtime = time(NULL);
|
|
70 mdate = gaim_utf8_strftime("%H:%M:%S", localtime(&mtime));
|
|
71 ts_s = g_strdup_printf("(%s) ", mdate);
|
|
72 } else {
|
|
73 ts_s = g_strdup("");
|
|
74 }
|
|
75
|
|
76 if (category == NULL)
|
|
77 g_print("%s%s", ts_s, arg_s);
|
|
78 else
|
|
79 g_print("%s%s: %s", ts_s, category, arg_s);
|
|
80
|
|
81 g_free(ts_s);
|
|
82 }
|
|
83
|
|
84 if (ops != NULL && ops->print != NULL)
|
|
85 ops->print(level, category, arg_s);
|
|
86
|
|
87 g_free(arg_s);
|
|
88 }
|
|
89
|
|
90 void
|
|
91 gaim_debug(GaimDebugLevel level, const char *category,
|
|
92 const char *format, ...)
|
|
93 {
|
|
94 va_list args;
|
|
95
|
|
96 g_return_if_fail(level != GAIM_DEBUG_ALL);
|
|
97 g_return_if_fail(format != NULL);
|
|
98
|
|
99 va_start(args, format);
|
|
100 gaim_debug_vargs(level, category, format, args);
|
|
101 va_end(args);
|
|
102 }
|
|
103
|
|
104 void
|
|
105 gaim_debug_misc(const char *category, const char *format, ...)
|
|
106 {
|
|
107 va_list args;
|
|
108
|
|
109 g_return_if_fail(format != NULL);
|
|
110
|
|
111 va_start(args, format);
|
|
112 gaim_debug_vargs(GAIM_DEBUG_MISC, category, format, args);
|
|
113 va_end(args);
|
|
114 }
|
|
115
|
|
116 void
|
|
117 gaim_debug_info(const char *category, const char *format, ...)
|
|
118 {
|
|
119 va_list args;
|
|
120
|
|
121 g_return_if_fail(format != NULL);
|
|
122
|
|
123 va_start(args, format);
|
|
124 gaim_debug_vargs(GAIM_DEBUG_INFO, category, format, args);
|
|
125 va_end(args);
|
|
126 }
|
|
127
|
|
128 void
|
|
129 gaim_debug_warning(const char *category, const char *format, ...)
|
|
130 {
|
|
131 va_list args;
|
|
132
|
|
133 g_return_if_fail(format != NULL);
|
|
134
|
|
135 va_start(args, format);
|
|
136 gaim_debug_vargs(GAIM_DEBUG_WARNING, category, format, args);
|
|
137 va_end(args);
|
|
138 }
|
|
139
|
|
140 void
|
|
141 gaim_debug_error(const char *category, const char *format, ...)
|
|
142 {
|
|
143 va_list args;
|
|
144
|
|
145 g_return_if_fail(format != NULL);
|
|
146
|
|
147 va_start(args, format);
|
|
148 gaim_debug_vargs(GAIM_DEBUG_ERROR, category, format, args);
|
|
149 va_end(args);
|
|
150 }
|
|
151
|
|
152 void
|
|
153 gaim_debug_fatal(const char *category, const char *format, ...)
|
|
154 {
|
|
155 va_list args;
|
|
156
|
|
157 g_return_if_fail(format != NULL);
|
|
158
|
|
159 va_start(args, format);
|
|
160 gaim_debug_vargs(GAIM_DEBUG_FATAL, category, format, args);
|
|
161 va_end(args);
|
|
162 }
|
|
163
|
|
164 void
|
|
165 gaim_debug_set_enabled(gboolean enabled)
|
|
166 {
|
|
167 debug_enabled = enabled;
|
|
168 }
|
|
169
|
|
170 gboolean
|
|
171 gaim_debug_is_enabled()
|
|
172 {
|
|
173 return debug_enabled;
|
|
174 }
|
|
175
|
|
176 void
|
|
177 gaim_debug_set_ui_ops(GaimDebugUiOps *ops)
|
|
178 {
|
|
179 debug_ui_ops = ops;
|
|
180 }
|
|
181
|
|
182 GaimDebugUiOps *
|
|
183 gaim_debug_get_ui_ops(void)
|
|
184 {
|
|
185 return debug_ui_ops;
|
|
186 }
|
|
187
|
|
188 void
|
|
189 gaim_debug_init(void)
|
|
190 {
|
|
191 gaim_prefs_add_none("/core/debug");
|
|
192
|
|
193 /*
|
|
194 * This pref is currently used by both the console
|
|
195 * output and the debug window output.
|
|
196 */
|
|
197 gaim_prefs_add_bool("/core/debug/timestamps", FALSE);
|
|
198 }
|