comparison src/debug.c @ 10307:2ac21bf20e04

[gaim-migrate @ 11497] And another one gone, and another one gone, another one bites the dust. Hopefully I'm committing everything this time. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 03 Dec 2004 02:46:34 +0000
parents fa6395637e2c
children 6a20307ef8dc
comparison
equal deleted inserted replaced
10306:56cc5d49472b 10307:2ac21bf20e04
21 * You should have received a copy of the GNU General Public License 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 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 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */ 24 */
25 #include "debug.h" 25 #include "debug.h"
26 #include <stdio.h> 26 #include "internal.h"
27 #include <stdlib.h> 27 #include "prefs.h"
28 #include <glib.h>
29 28
30 static GaimDebugUiOps *debug_ui_ops = NULL; 29 static GaimDebugUiOps *debug_ui_ops = NULL;
30
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;
31 42
32 void 43 void
33 gaim_debug_vargs(GaimDebugLevel level, const char *category, 44 gaim_debug_vargs(GaimDebugLevel level, const char *category,
34 const char *format, va_list args) 45 const char *format, va_list args)
35 { 46 {
36 GaimDebugUiOps *ops; 47 GaimDebugUiOps *ops;
37 48
38 g_return_if_fail(level != GAIM_DEBUG_ALL); 49 g_return_if_fail(level != GAIM_DEBUG_ALL);
39 g_return_if_fail(format != NULL); 50 g_return_if_fail(format != NULL);
51
52 if (debug_enabled) {
53 gchar *arg_s, *ts_s;
54 gboolean timestamps;
55
56 arg_s = g_strdup_vprintf(format, args);
57
58 timestamps = gaim_prefs_get_bool("/core/debug/timestamps");;
59 if ((category != NULL) && (timestamps)) {
60 gchar mdate[64];
61
62 time_t mtime = time(NULL);
63 strftime(mdate, sizeof(mdate), "%H:%M:%S", localtime(&mtime));
64 ts_s = g_strdup_printf("(%s) ", mdate);
65 } else {
66 ts_s = g_strdup("");
67 }
68
69 if (category == NULL)
70 g_print("%s%s", ts_s, arg_s);
71 else
72 g_print("%s%s: %s", ts_s, category, arg_s);
73
74 g_free(arg_s);
75 g_free(ts_s);
76 }
40 77
41 ops = gaim_debug_get_ui_ops(); 78 ops = gaim_debug_get_ui_ops();
42 79
43 if (ops != NULL && ops->print != NULL) 80 if (ops != NULL && ops->print != NULL)
44 ops->print(level, category, format, args); 81 ops->print(level, category, format, args);
117 gaim_debug_vargs(GAIM_DEBUG_FATAL, category, format, args); 154 gaim_debug_vargs(GAIM_DEBUG_FATAL, category, format, args);
118 va_end(args); 155 va_end(args);
119 } 156 }
120 157
121 void 158 void
159 gaim_debug_set_enabled(gboolean enabled)
160 {
161 debug_enabled = enabled;
162 }
163
164 gboolean
165 gaim_debug_is_enabled()
166 {
167 return debug_enabled;
168 }
169
170 void
122 gaim_debug_set_ui_ops(GaimDebugUiOps *ops) 171 gaim_debug_set_ui_ops(GaimDebugUiOps *ops)
123 { 172 {
124 debug_ui_ops = ops; 173 debug_ui_ops = ops;
125 } 174 }
126 175
127 GaimDebugUiOps * 176 GaimDebugUiOps *
128 gaim_debug_get_ui_ops(void) 177 gaim_debug_get_ui_ops(void)
129 { 178 {
130 return debug_ui_ops; 179 return debug_ui_ops;
131 } 180 }
181
182 void
183 gaim_debug_init(void)
184 {
185 gaim_prefs_add_none("/core/debug");
186
187 /*
188 * This pref is currently used by both the console
189 * output and the debug window output.
190 */
191 gaim_prefs_add_bool("/core/debug/timestamps", FALSE);
192 }