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.
25 short DebugLevel = -1;
26 FILE* DebugFile = NULL;
28 void debug_setlevel (short level) {
32 void debug_start (const char* basedir) {
35 char buf[_POSIX_PATH_MAX];
36 char buf2[_POSIX_PATH_MAX];
38 if (DebugLevel < DEBUG_MIN_LEVEL || DebugLevel > DEBUG_MAX_LEVEL
39 || !basedir || !*basedir)
41 /* rotate the old debug logs */
42 for (i = 3; i >= 0; i--) {
43 snprintf (buf, sizeof (buf), "%s/.muttngdebug%d", NONULL (basedir), i);
44 snprintf (buf2, sizeof (buf2), "%s/.muttngdebug%d", NONULL (basedir), i + 1);
47 if ((DebugFile = safe_fopen (buf, "w")) != NULL) {
49 setbuf (DebugFile, NULL); /* don't buffer the debugging output! */
51 "Mutt-ng %s started at %s\nDebugging at level %d\n\n",
52 MUTT_VERSION, asctime (localtime (&t)), DebugLevel);
56 void _debug_print_intro (const char* file, int line, const char* function, int level) {
57 if (!DebugFile || DebugLevel < DEBUG_MIN_LEVEL || DebugLevel > DEBUG_MAX_LEVEL)
59 fprintf (DebugFile, "[%d:%s:%d", level, NONULL(file), line);
60 if (function && *function)
61 fprintf (DebugFile, ":%s()", function);
62 fprintf (DebugFile, "] ");
65 void _debug_print_msg (const char* fmt, ...) {
68 if (!DebugFile || DebugLevel < 0)
71 vfprintf (DebugFile, fmt, ap);