Mercurial > pidgin.yaz
annotate src/debug.c @ 13997:1c411ca5590c
[gaim-migrate @ 16582]
Memory leak plug
committer: Tailor Script <tailor@pidgin.im>
author | Aaron Sheldon <aaronsheldon> |
---|---|
date | Thu, 27 Jul 2006 02:20:33 +0000 |
parents | 756c3d7177d9 |
children |
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" | |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
11504
diff
changeset
|
28 #include "util.h" |
5212 | 29 |
30 static GaimDebugUiOps *debug_ui_ops = NULL; | |
31 | |
10307 | 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 | |
11504
921f64947cad
[gaim-migrate @ 13749]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
44 static void |
5212 | 45 gaim_debug_vargs(GaimDebugLevel level, const char *category, |
46 const char *format, va_list args) | |
47 { | |
48 GaimDebugUiOps *ops; | |
13926 | 49 char *arg_s = NULL; |
5212 | 50 |
51 g_return_if_fail(level != GAIM_DEBUG_ALL); | |
52 g_return_if_fail(format != NULL); | |
53 | |
13926 | 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 | |
10307 | 61 if (debug_enabled) { |
13926 | 62 gchar *ts_s; |
10307 | 63 |
10448 | 64 if ((category != NULL) && |
65 (gaim_prefs_exists("/core/debug/timestamps")) && | |
66 (gaim_prefs_get_bool("/core/debug/timestamps"))) { | |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
11504
diff
changeset
|
67 const char *mdate; |
10307 | 68 |
69 time_t mtime = time(NULL); | |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
11504
diff
changeset
|
70 mdate = gaim_utf8_strftime("%H:%M:%S", localtime(&mtime)); |
10307 | 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 | |
13926 | 84 if (ops != NULL && ops->print != NULL) |
85 ops->print(level, category, arg_s); | |
5212 | 86 |
13926 | 87 g_free(arg_s); |
5212 | 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 | |
6721
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
105 gaim_debug_misc(const char *category, const char *format, ...) |
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_list args; |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
108 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
109 g_return_if_fail(format != NULL); |
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 va_start(args, format); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
112 gaim_debug_vargs(GAIM_DEBUG_MISC, category, format, args); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
113 va_end(args); |
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 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
116 void |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
117 gaim_debug_info(const char *category, const char *format, ...) |
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_list args; |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
120 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
121 g_return_if_fail(format != NULL); |
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 va_start(args, format); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
124 gaim_debug_vargs(GAIM_DEBUG_INFO, category, format, args); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
125 va_end(args); |
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 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
128 void |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
129 gaim_debug_warning(const char *category, const char *format, ...) |
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_list args; |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
132 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
133 g_return_if_fail(format != NULL); |
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 va_start(args, format); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
136 gaim_debug_vargs(GAIM_DEBUG_WARNING, category, format, args); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
137 va_end(args); |
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 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
140 void |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
141 gaim_debug_error(const char *category, const char *format, ...) |
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_list args; |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
144 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
145 g_return_if_fail(format != NULL); |
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 va_start(args, format); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
148 gaim_debug_vargs(GAIM_DEBUG_ERROR, category, format, args); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
149 va_end(args); |
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 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
152 void |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
153 gaim_debug_fatal(const char *category, const char *format, ...) |
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_list args; |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
156 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
157 g_return_if_fail(format != NULL); |
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 va_start(args, format); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
160 gaim_debug_vargs(GAIM_DEBUG_FATAL, category, format, args); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
161 va_end(args); |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
162 } |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
163 |
acc4376ce062
[gaim-migrate @ 7248]
Christian Hammond <chipx86@chipx86.com>
parents:
6483
diff
changeset
|
164 void |
10307 | 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 | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6721
diff
changeset
|
177 gaim_debug_set_ui_ops(GaimDebugUiOps *ops) |
5212 | 178 { |
179 debug_ui_ops = ops; | |
180 } | |
181 | |
182 GaimDebugUiOps * | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6721
diff
changeset
|
183 gaim_debug_get_ui_ops(void) |
5212 | 184 { |
185 return debug_ui_ops; | |
186 } | |
10307 | 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 } |