2 * written for mutt-ng by:
3 * Rocco Rutte <pdmef@cs.tu-berlin.de>
5 * This file is part of mutt-ng, see http://www.muttng.org/.
6 * It's licensed under the GNU General Public License,
7 * please see the file GPL in the top level source directory.
19 #include <lib-lib/str.h>
20 #include <lib-lib/file.h>
26 short DebugLevel = -1;
27 FILE* DebugFile = NULL;
29 void debug_setlevel (short level) {
33 void debug_start (const char* basedir) {
36 char buf[_POSIX_PATH_MAX];
37 char buf2[_POSIX_PATH_MAX];
39 if (DebugLevel < DEBUG_MIN_LEVEL || DebugLevel > DEBUG_MAX_LEVEL
40 || !basedir || !*basedir)
42 /* rotate the old debug logs */
43 for (i = 3; i >= 0; i--) {
44 snprintf (buf, sizeof (buf), "%s/.muttngdebug%d", NONULL (basedir), i);
45 snprintf (buf2, sizeof (buf2), "%s/.muttngdebug%d", NONULL (basedir), i + 1);
48 if ((DebugFile = safe_fopen (buf, "w")) != NULL) {
50 setbuf (DebugFile, NULL); /* don't buffer the debugging output! */
52 "Mutt-ng %s started at %s\nDebugging at level %d\n\n",
53 MUTT_VERSION, asctime (localtime (&t)), DebugLevel);
57 void _debug_print_intro (const char* file, int line, const char* function, int level) {
58 if (!DebugFile || DebugLevel < DEBUG_MIN_LEVEL || DebugLevel > DEBUG_MAX_LEVEL)
60 fprintf (DebugFile, "[%d:%s:%d", level, NONULL(file), line);
61 if (function && *function)
62 fprintf (DebugFile, ":%s()", function);
63 fprintf (DebugFile, "] ");
66 void _debug_print_msg (const char* fmt, ...) {
69 if (!DebugFile || DebugLevel < 0)
72 vfprintf (DebugFile, fmt, ap);