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 Purple 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 purple_debug_vargs(PurpleDebugLevel level
, const char *category
,
47 const char *format
, va_list args
)
49 PurpleDebugUiOps
*ops
;
52 g_return_if_fail(level
!= PURPLE_DEBUG_ALL
);
53 g_return_if_fail(format
!= NULL
);
55 ops
= purple_debug_get_ui_ops();
57 if (!debug_enabled
&& ((ops
== NULL
) || (ops
->print
== NULL
) ||
58 (ops
->is_enabled
&& !ops
->is_enabled(level
, category
))))
61 arg_s
= g_strdup_vprintf(format
, args
);
66 time_t mtime
= time(NULL
);
69 mdate
= purple_utf8_strftime("%H:%M:%S", localtime(&mtime
));
70 ts_s
= g_strdup_printf("(%s) ", mdate
);
73 g_print("%s%s", ts_s
, arg_s
);
75 g_print("%s%s: %s", ts_s
, category
, arg_s
);
80 if (ops
!= NULL
&& ops
->print
!= NULL
)
81 ops
->print(level
, category
, arg_s
);
87 purple_debug(PurpleDebugLevel level
, const char *category
,
88 const char *format
, ...)
92 g_return_if_fail(level
!= PURPLE_DEBUG_ALL
);
93 g_return_if_fail(format
!= NULL
);
95 va_start(args
, format
);
96 purple_debug_vargs(level
, category
, format
, args
);
101 purple_debug_misc(const char *category
, const char *format
, ...)
105 g_return_if_fail(format
!= NULL
);
107 va_start(args
, format
);
108 purple_debug_vargs(PURPLE_DEBUG_MISC
, category
, format
, args
);
113 purple_debug_info(const char *category
, const char *format
, ...)
117 g_return_if_fail(format
!= NULL
);
119 va_start(args
, format
);
120 purple_debug_vargs(PURPLE_DEBUG_INFO
, category
, format
, args
);
125 purple_debug_warning(const char *category
, const char *format
, ...)
129 g_return_if_fail(format
!= NULL
);
131 va_start(args
, format
);
132 purple_debug_vargs(PURPLE_DEBUG_WARNING
, category
, format
, args
);
137 purple_debug_error(const char *category
, const char *format
, ...)
141 g_return_if_fail(format
!= NULL
);
143 va_start(args
, format
);
144 purple_debug_vargs(PURPLE_DEBUG_ERROR
, category
, format
, args
);
149 purple_debug_fatal(const char *category
, const char *format
, ...)
153 g_return_if_fail(format
!= NULL
);
155 va_start(args
, format
);
156 purple_debug_vargs(PURPLE_DEBUG_FATAL
, category
, format
, args
);
161 purple_debug_set_enabled(gboolean enabled
)
163 debug_enabled
= enabled
;
167 purple_debug_is_enabled()
169 return debug_enabled
;
173 purple_debug_set_ui_ops(PurpleDebugUiOps
*ops
)
179 purple_debug_get_ui_ops(void)
185 purple_debug_init(void)
187 purple_prefs_add_none("/purple/debug");
190 * This pref is obsolete and no longer referenced anywhere. It only
191 * survives here because it would be an API break if we removed it.
192 * Remove this when we get to 3.0.0 :)
194 purple_prefs_add_bool("/purple/debug/timestamps", TRUE
);