Mercurial > pidgin.yaz
annotate src/debug.c @ 11243:a511b77a368b
[gaim-migrate @ 13408]
sf patch #1246384, from shiyee
"This patch globally defines
spacings and boreders according to the Gnome Human
Interfaces Guidelines, and uses those defines where
appropriate. No visual changes are made, but the the
intention is that the defines should help promote
uniformness."
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 12 Aug 2005 23:53:28 +0000 |
parents | 50224ac8184d |
children | bb0d7b719af2 |
rev | line source |
---|---|
5212 | 1 /** |
2 * @file debug.c Debug API | |
3 * @ingroup core | |
4 * | |
5 * gaim | |
6 * | |
8046 | 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. | |
6483
565339a6eb86
[gaim-migrate @ 6997]
Christian Hammond <chipx86@chipx86.com>
parents:
5212
diff
changeset
|
10 * |
5212 | 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" | |
10307 | 26 #include "internal.h" |
27 #include "prefs.h" | |
5212 | 28 |
29 static GaimDebugUiOps *debug_ui_ops = NULL; | |
30 | |
10307 | 31 /* |
32 * This determines whether debug info should be written to the | |
33 * console or not. | |
34 * | |
35 * It doesn't make sense to make this a normal Gaim preference | |
36 * because it's a command line option. This will always be FALSE, | |
37 * unless the user explicitly started Gaim with the -d flag. | |
38 * It doesn't matter what this value was the last time Gaim was | |
39 * started, so it doesn't make sense to save it in prefs. | |
40 */ | |
41 static gboolean debug_enabled = FALSE; | |
42 | |
11033
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
43 /* XXX I want to make this static but gg uses this for internal debug level |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
44 * stuff and I don't really feel like unwrapping it right now. -Etan */ |
5212 | 45 void |
46 gaim_debug_vargs(GaimDebugLevel level, const char *category, | |
47 const char *format, va_list args) | |
48 { | |
49 GaimDebugUiOps *ops; | |
50 | |
51 g_return_if_fail(level != GAIM_DEBUG_ALL); | |
52 g_return_if_fail(format != NULL); | |
53 | |
10307 | 54 if (debug_enabled) { |
55 gchar *arg_s, *ts_s; | |
56 | |
57 arg_s = g_strdup_vprintf(format, args); | |
58 | |
10448 | 59 if ((category != NULL) && |
60 (gaim_prefs_exists("/core/debug/timestamps")) && | |
61 (gaim_prefs_get_bool("/core/debug/timestamps"))) { | |
10307 | 62 gchar mdate[64]; |
63 | |
64 time_t mtime = time(NULL); | |
65 strftime(mdate, sizeof(mdate), "%H:%M:%S", localtime(&mtime)); | |
66 ts_s = g_strdup_printf("(%s) ", mdate); | |
67 } else { | |
68 ts_s = g_strdup(""); | |
69 } | |
70 | |
71 if (category == NULL) | |
72 g_print("%s%s", ts_s, arg_s); | |
73 else | |
74 g_print("%s%s: %s", ts_s, category, arg_s); | |
75 | |
76 g_free(arg_s); | |
77 g_free(ts_s); | |
78 } | |
79 | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6721
diff
changeset
|
80 ops = gaim_debug_get_ui_ops(); |
5212 | 81 |
82 if (ops != NULL && ops->print != NULL) | |
83 ops->print(level, category, format, args); | |
84 } | |
85 | |
86 void | |
87 gaim_debug(GaimDebugLevel level, const char *category, | |
88 const char *format, ...) | |
89 { | |
90 va_list args; | |
91 | |
92 g_return_if_fail(level != GAIM_DEBUG_ALL); | |
93 g_return_if_fail(format != NULL); | |
94 | |
95 va_start(args, format); | |
96 gaim_debug_vargs(level, category, format, args); | |
97 va_end(args); | |
98 } | |
99 | |
100 void | |
6721
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
101 gaim_debug_misc(const char *category, const char *format, ...) |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
102 { |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
103 va_list args; |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
104 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
105 g_return_if_fail(format != NULL); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
106 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
107 va_start(args, format); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
108 gaim_debug_vargs(GAIM_DEBUG_MISC, category, format, args); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
109 va_end(args); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
110 } |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
111 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
112 void |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
113 gaim_debug_info(const char *category, const char *format, ...) |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
114 { |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
115 va_list args; |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
116 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
117 g_return_if_fail(format != NULL); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
118 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
119 va_start(args, format); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
120 gaim_debug_vargs(GAIM_DEBUG_INFO, category, format, args); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
121 va_end(args); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
122 } |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
123 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
124 void |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
125 gaim_debug_warning(const char *category, const char *format, ...) |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
126 { |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
127 va_list args; |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
128 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
129 g_return_if_fail(format != NULL); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
130 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
131 va_start(args, format); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
132 gaim_debug_vargs(GAIM_DEBUG_WARNING, category, format, args); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
133 va_end(args); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
134 } |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
135 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
136 void |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
137 gaim_debug_error(const char *category, const char *format, ...) |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
138 { |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
139 va_list args; |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
140 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
141 g_return_if_fail(format != NULL); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
142 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
143 va_start(args, format); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
144 gaim_debug_vargs(GAIM_DEBUG_ERROR, category, format, args); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
145 va_end(args); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
146 } |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
147 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
148 void |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
149 gaim_debug_fatal(const char *category, const char *format, ...) |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
150 { |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
151 va_list args; |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
152 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
153 g_return_if_fail(format != NULL); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
154 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
155 va_start(args, format); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
156 gaim_debug_vargs(GAIM_DEBUG_FATAL, category, format, args); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
157 va_end(args); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
158 } |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
159 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
160 void |
11033
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
161 gaim_debug_register_category(const char *category) |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
162 { |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
163 GaimDebugUiOps *ops; |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
164 |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
165 g_return_if_fail(category != NULL); |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
166 |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
167 ops = gaim_debug_get_ui_ops(); |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
168 |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
169 if (ops != NULL && ops->register_category != NULL) |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
170 ops->register_category(category); |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
171 } |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
172 |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
173 void |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
174 gaim_debug_unregister_category(const char *category) |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
175 { |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
176 GaimDebugUiOps *ops; |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
177 |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
178 g_return_if_fail(category != NULL); |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
179 |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
180 ops = gaim_debug_get_ui_ops(); |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
181 |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
182 if (ops != NULL && ops->unregister_category != NULL) |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
183 ops->unregister_category(category); |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
184 } |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
185 |
50224ac8184d
[gaim-migrate @ 12919]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10448
diff
changeset
|
186 void |
10307 | 187 gaim_debug_set_enabled(gboolean enabled) |
188 { | |
189 debug_enabled = enabled; | |
190 } | |
191 | |
192 gboolean | |
193 gaim_debug_is_enabled() | |
194 { | |
195 return debug_enabled; | |
196 } | |
197 | |
198 void | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6721
diff
changeset
|
199 gaim_debug_set_ui_ops(GaimDebugUiOps *ops) |
5212 | 200 { |
201 debug_ui_ops = ops; | |
202 } | |
203 | |
204 GaimDebugUiOps * | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6721
diff
changeset
|
205 gaim_debug_get_ui_ops(void) |
5212 | 206 { |
207 return debug_ui_ops; | |
208 } | |
10307 | 209 |
210 void | |
211 gaim_debug_init(void) | |
212 { | |
213 gaim_prefs_add_none("/core/debug"); | |
214 | |
215 /* | |
216 * This pref is currently used by both the console | |
217 * output and the debug window output. | |
218 */ | |
219 gaim_prefs_add_bool("/core/debug/timestamps", FALSE); | |
220 } |