]> git.ipfire.org Git - thirdparty/squid.git/blame - src/Debug.h
cert validation cache: fix to build on amd64-CentOS-5.3
[thirdparty/squid.git] / src / Debug.h
CommitLineData
c772f001 1/*
b510f3a1 2 * DEBUG: section 00 Debug Routines
c772f001 3 * AUTHOR: Harvest Derived
4 *
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
7 *
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
26ac0430 21 *
c772f001 22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26ac0430 26 *
c772f001 27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
30 *
31 */
e1f7507e
AJ
32#ifndef SQUID_DEBUG_H
33#define SQUID_DEBUG_H
c772f001 34
27e059d4 35#if HAVE_IOSTREAM
f95fe6ed 36#include <iostream>
27e059d4
AJ
37#endif
38
a8d99c60 39#undef assert
27e059d4 40#if HAVE_SSTREAM
f95fe6ed 41#include <sstream>
27e059d4
AJ
42#endif
43#if HAVE_IOMANIP
bf8fe701 44#include <iomanip>
27e059d4
AJ
45#endif
46#if defined(assert)
a8d99c60 47#undef assert
48#endif
27e059d4 49
a8d99c60 50#if PURIFY
51#define assert(EX) ((void)0)
52#elif defined(NODEBUG)
53#define assert(EX) ((void)0)
54#elif STDC_HEADERS
55#define assert(EX) ((EX)?((void)0):xassert( # EX , __FILE__, __LINE__))
56#else
57#define assert(EX) ((EX)?((void)0):xassert("EX", __FILE__, __LINE__))
58#endif
f95fe6ed 59
62493678
AJ
60/* context-based debugging, the actual type is subject to change */
61typedef int Ctx;
8a648e8d
FC
62Ctx ctx_enter(const char *descr);
63void ctx_exit(Ctx ctx);
62493678 64
e1f7507e
AJ
65/* defined debug section limits */
66#define MAX_DEBUG_SECTIONS 100
67
feefade1 68/* defined names for Debug Levels */
69#define DBG_CRITICAL 0 /**< critical messages always shown when they occur */
70#define DBG_IMPORTANT 1 /**< important messages always shown when their section is being checked */
71/* levels 2-8 are still being discussed amongst the developers */
72#define DBG_DATA 9 /**< output is a large data dump only necessary for advanced debugging */
73
bbbea8ad
AJ
74#define DBG_PARSE_NOTE(x) (opt_parse_cfg_only?0:(x)) /**< output is always to be displayed on '-k parse' but at level-x normally. */
75
62e76326 76class Debug
c772f001 77{
62e76326 78
c772f001 79public:
62493678
AJ
80 static char *debugOptions;
81 static char *cache_log;
82 static int rotateNumber;
62e76326 83 static int Levels[MAX_DEBUG_SECTIONS];
84 static int level;
62493678
AJ
85 static int override_X;
86 static int log_stderr;
87 static bool log_syslog;
88
f95fe6ed 89 static std::ostream &getDebugOut();
90 static void finishDebug();
d9e04dc7 91 static void parseOptions(char const *);
f95fe6ed 92
93private:
9eab365d 94 // Hack: replaces global ::xassert() to debug debugging assertions
95 static void xassert(const char *msg, const char *file, int line);
26ac0430 96
4ecaa0f0 97 static std::ostringstream *CurrentDebug;
9eab365d 98 static int TheDepth; // level of nested debugging calls
c772f001 99};
100
f76d2f97
AJ
101extern FILE *debug_log;
102
881c4733 103size_t BuildPrefixInit();
af28bfbd
AJ
104const char * SkipBuildPrefix(const char* path);
105
f95fe6ed 106/* Debug stream */
107#define debugs(SECTION, LEVEL, CONTENT) \
108 do { \
109 if ((Debug::level = (LEVEL)) <= Debug::Levels[SECTION]) { \
bfd38d03 110 std::ostream &_dbo=Debug::getDebugOut(); \
d224691d 111 if (Debug::level > DBG_IMPORTANT) \
bfd38d03
FC
112 _dbo << SkipBuildPrefix(__FILE__)<<"("<<__LINE__<<") "<<__FUNCTION__<<": "; \
113 _dbo << CONTENT; \
114 Debug::finishDebug(); \
f95fe6ed 115 } \
116 } while (/*CONSTCOND*/ 0)
117
fc9d2eb0
FC
118/** stream manipulator which does nothing.
119 * \deprecated Do not add to new code, and remove when editing old code
def17b6a 120 *
fc9d2eb0
FC
121 * Its purpose is to inactivate calls made following previous debugs()
122 * guidelines such as
23d6095a 123 * debugs(1,2, HERE << "some message");
fc9d2eb0
FC
124 *
125 * His former objective is now absorbed in the debugs call itself
def17b6a 126 */
fc9d2eb0
FC
127inline std::ostream&
128HERE(std::ostream& s)
129{
130 return s;
131}
def17b6a 132
23d6095a
AJ
133/*
134 * MYNAME is for use at debug levels 0 and 1 where HERE is too messy.
135 *
136 * debugs(1,1, MYNAME << "WARNING: some message");
137 */
138#ifdef __PRETTY_FUNCTION__
139#define MYNAME __PRETTY_FUNCTION__ << " "
140#else
141#define MYNAME __FUNCTION__ << " "
142#endif
143
cc192b50 144/* some uint8_t do not like streaming control-chars (values 0-31, 127+) */
26ac0430
AJ
145inline std::ostream& operator <<(std::ostream &os, const uint8_t d)
146{
066c9540 147 return (os << (int)d);
148}
149
96e03dd8 150/* Legacy debug style. Still used in some places. needs to die... */
2c87d96a
AJ
151#define do_debug(SECTION, LEVEL) ((Debug::level = (LEVEL)) <= Debug::Levels[SECTION])
152#define old_debug(SECTION, LEVEL) if do_debug((SECTION), (LEVEL)) _db_print
96e03dd8 153
ec85ebda 154/* Legacy debug function definitions */
8a648e8d
FC
155void _db_init(const char *logfile, const char *options);
156void _db_print(const char *,...) PRINTF_FORMAT_ARG1;
157void _db_set_syslog(const char *facility);
158void _db_rotate_log(void);
96e03dd8 159
e1f7507e 160#endif /* SQUID_DEBUG_H */