2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or (at
5 * your option) any later version.
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * Copyright © 2006 Pierre Habouzit
20 * written for mutt-ng by:
21 * Rocco Rutte <pdmef@cs.tu-berlin.de>
23 * This file is part of mutt-ng, see http://www.muttng.org/.
24 * It's licensed under the GNU General Public License,
25 * please see the file GPL in the top level source directory.
44 short DebugLevel = -1;
45 FILE* DebugFile = NULL;
47 void debug_setlevel(short level) {
51 void debug_start(const char* basedir) {
54 char buf[_POSIX_PATH_MAX];
55 char buf2[_POSIX_PATH_MAX];
57 if (DebugLevel < DEBUG_MIN_LEVEL || DebugLevel > DEBUG_MAX_LEVEL
58 || !basedir || !*basedir)
60 /* rotate the old debug logs */
61 for (i = 3; i >= 0; i--) {
62 snprintf(buf, sizeof (buf), "%s/.madmuttdebug%d", NONULL(basedir), i);
63 snprintf(buf2, sizeof (buf2), "%s/.madmuttdebug%d", NONULL(basedir), i + 1);
67 if ((DebugFile = safe_fopen (buf, "w")) != NULL) {
69 setbuf(DebugFile, NULL); /* don't buffer the debugging output! */
71 "Madmutt %s started at %s\nDebugging at level %d\n\n",
72 MUTT_VERSION, asctime (localtime (&t)), DebugLevel);
76 void _debug_print_intro(const char* file, int line, const char *function, int level) {
77 if (!DebugFile || DebugLevel < DEBUG_MIN_LEVEL || DebugLevel > DEBUG_MAX_LEVEL)
79 fprintf(DebugFile, "[%d:%s:%d", level, NONULL(file), line);
80 if (function && *function)
81 fprintf(DebugFile, ":%s()", function);
82 fprintf(DebugFile, "] ");
85 void _debug_print_msg (const char* fmt, ...) {
88 if (!DebugFile || DebugLevel < 0)
91 vfprintf(DebugFile, fmt, ap);