]> git.ipfire.org Git - thirdparty/squid.git/blob - src/Debug.h
Merge from trunk
[thirdparty/squid.git] / src / Debug.h
1 /*
2 * $Id$
3 *
4 * DEBUG: section 0 Debug Routines
5 * AUTHOR: Harvest Derived
6 *
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
9 *
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
32 *
33 */
34 #ifndef SQUID_DEBUG_H
35 #define SQUID_DEBUG_H
36
37 #include "config.h"
38
39 #if HAVE_IOSTREAM
40 #include <iostream>
41 #endif
42
43 #undef assert
44 #if HAVE_SSTREAM
45 #include <sstream>
46 #endif
47 #if HAVE_IOMANIP
48 #include <iomanip>
49 #endif
50 #if defined(assert)
51 #undef assert
52 #endif
53
54 #if PURIFY
55 #define assert(EX) ((void)0)
56 #elif defined(NODEBUG)
57 #define assert(EX) ((void)0)
58 #elif STDC_HEADERS
59 #define assert(EX) ((EX)?((void)0):xassert( # EX , __FILE__, __LINE__))
60 #else
61 #define assert(EX) ((EX)?((void)0):xassert("EX", __FILE__, __LINE__))
62 #endif
63
64 /* context-based debugging, the actual type is subject to change */
65 typedef int Ctx;
66
67 /* defined debug section limits */
68 #define MAX_DEBUG_SECTIONS 100
69
70 /* defined names for Debug Levels */
71 #define DBG_CRITICAL 0 /**< critical messages always shown when they occur */
72 #define DBG_IMPORTANT 1 /**< important messages always shown when their section is being checked */
73 /* levels 2-8 are still being discussed amongst the developers */
74 #define DBG_DATA 9 /**< output is a large data dump only necessary for advanced debugging */
75
76 class Debug
77 {
78
79 public:
80 static char *debugOptions;
81 static char *cache_log;
82 static int rotateNumber;
83 static int Levels[MAX_DEBUG_SECTIONS];
84 static int level;
85 static int override_X;
86 static int log_stderr;
87 static bool log_syslog;
88
89 static std::ostream &getDebugOut();
90 static void finishDebug();
91 static void parseOptions(char const *);
92
93 private:
94 // Hack: replaces global ::xassert() to debug debugging assertions
95 static void xassert(const char *msg, const char *file, int line);
96
97 static std::ostringstream *CurrentDebug;
98 static int TheDepth; // level of nested debugging calls
99 };
100
101 extern FILE *debug_log;
102
103 const size_t BuildPrefixInit();
104 const char * SkipBuildPrefix(const char* path);
105
106 /* Debug stream */
107 #define debugs(SECTION, LEVEL, CONTENT) \
108 do { \
109 if ((Debug::level = (LEVEL)) <= Debug::Levels[SECTION]) { \
110 Debug::getDebugOut() << CONTENT; \
111 Debug::finishDebug(); \
112 } \
113 } while (/*CONSTCOND*/ 0)
114
115 /*
116 * HERE is a macro that you can use like this:
117 *
118 * debugs(1,2, HERE << "some message");
119 */
120 #define HERE SkipBuildPrefix(__FILE__)<<"("<<__LINE__<<") "<<__FUNCTION__<<": "
121
122 /*
123 * MYNAME is for use at debug levels 0 and 1 where HERE is too messy.
124 *
125 * debugs(1,1, MYNAME << "WARNING: some message");
126 */
127 #ifdef __PRETTY_FUNCTION__
128 #define MYNAME __PRETTY_FUNCTION__ << " "
129 #else
130 #define MYNAME __FUNCTION__ << " "
131 #endif
132
133 /* some uint8_t do not like streaming control-chars (values 0-31, 127+) */
134 inline std::ostream& operator <<(std::ostream &os, const uint8_t d)
135 {
136 return (os << (int)d);
137 }
138
139 /* Legacy debug style. Still used in some places. needs to die... */
140 #define do_debug(SECTION, LEVEL) ((Debug::level = (LEVEL)) > Debug::Levels[SECTION])
141 #define old_debug(SECTION, LEVEL) \
142 do_debug(SECTION, LEVEL) ? (void) 0 : _db_print
143
144
145 #endif /* SQUID_DEBUG_H */