2 * @file debug.c Debug API
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
31 static PurpleDebugUiOps
*debug_ui_ops
= NULL
;
34 * This determines whether debug info should be written to the
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
;
54 purple_debug_vargs(PurpleDebugLevel level
, const char *category
,
55 const char *format
, va_list args
)
57 PurpleDebugUiOps
*ops
;
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
))))
69 arg_s
= g_strdup_vprintf(format
, args
);
74 time_t mtime
= time(NULL
);
77 mdate
= purple_utf8_strftime("%H:%M:%S", localtime(&mtime
));
78 ts_s
= g_strdup_printf("(%s) ", mdate
);
81 g_print("%s%s", ts_s
, arg_s
);
83 g_print("%s%s: %s", ts_s
, category
, arg_s
);
88 if (ops
!= NULL
&& ops
->print
!= NULL
)
89 ops
->print(level
, category
, arg_s
);
95 purple_debug(PurpleDebugLevel level
, const char *category
,
96 const char *format
, ...)
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
);
109 purple_debug_misc(const char *category
, const char *format
, ...)
113 g_return_if_fail(format
!= NULL
);
115 va_start(args
, format
);
116 purple_debug_vargs(PURPLE_DEBUG_MISC
, category
, format
, args
);
121 purple_debug_info(const char *category
, const char *format
, ...)
125 g_return_if_fail(format
!= NULL
);
127 va_start(args
, format
);
128 purple_debug_vargs(PURPLE_DEBUG_INFO
, category
, format
, args
);
133 purple_debug_warning(const char *category
, const char *format
, ...)
137 g_return_if_fail(format
!= NULL
);
139 va_start(args
, format
);
140 purple_debug_vargs(PURPLE_DEBUG_WARNING
, category
, format
, args
);
145 purple_debug_error(const char *category
, const char *format
, ...)
149 g_return_if_fail(format
!= NULL
);
151 va_start(args
, format
);
152 purple_debug_vargs(PURPLE_DEBUG_ERROR
, category
, format
, args
);
157 purple_debug_fatal(const char *category
, const char *format
, ...)
161 g_return_if_fail(format
!= NULL
);
163 va_start(args
, format
);
164 purple_debug_vargs(PURPLE_DEBUG_FATAL
, category
, format
, args
);
169 purple_debug_set_enabled(gboolean enabled
)
171 debug_enabled
= enabled
;
175 purple_debug_is_enabled()
177 return debug_enabled
;
181 purple_debug_set_ui_ops(PurpleDebugUiOps
*ops
)
187 purple_debug_is_verbose()
189 return debug_verbose
;
193 purple_debug_set_verbose(gboolean verbose
)
195 debug_verbose
= verbose
;
199 purple_debug_is_unsafe()
205 purple_debug_set_unsafe(gboolean unsafe
)
207 debug_unsafe
= unsafe
;
211 purple_debug_get_ui_ops(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
);