]> git.ipfire.org Git - thirdparty/squid.git/blame - src/tests/stub_debug.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / tests / stub_debug.cc
CommitLineData
4e0938ef 1/*
bde978a6 2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
4e0938ef
AJ
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
25f98340
AJ
9/*
10 * A stub implementation of the Debug.h API.
11 * For use by test binaries which do not need the full context debugging
54311b70
FC
12 *
13 * Note: it doesn't use the STUB API as the functions defined here must
14 * not abort the unit test.
25f98340 15 */
f7f3304a 16#include "squid.h"
25f98340
AJ
17#include "Debug.h"
18
25f98340
AJ
19FILE *debug_log = NULL;
20int Debug::TheDepth = 0;
21
22char *Debug::debugOptions;
23char *Debug::cache_log= NULL;
24int Debug::rotateNumber = 0;
25int Debug::Levels[MAX_DEBUG_SECTIONS];
26int Debug::level;
be039a68 27int Debug::sectionLevel;
25f98340
AJ
28int Debug::override_X = 0;
29int Debug::log_stderr = 1;
30bool Debug::log_syslog = false;
31
32Ctx
ced8def3 33ctx_enter(const char *)
25f98340
AJ
34{
35 return -1;
36}
37
38void
ced8def3
AJ
39ctx_exit(Ctx)
40{}
25f98340
AJ
41
42void
ced8def3 43_db_init(const char *, const char *)
25f98340
AJ
44{}
45
46void
ced8def3 47_db_set_syslog(const char *)
25f98340
AJ
48{}
49
50void
51_db_rotate_log(void)
52{}
53
54static void
55_db_print_stderr(const char *format, va_list args);
56
57void
58_db_print(const char *format,...)
59{
60 static char f[BUFSIZ];
61 va_list args1;
62 va_list args2;
63 va_list args3;
64
65 va_start(args1, format);
66 va_start(args2, format);
67 va_start(args3, format);
68
69 snprintf(f, BUFSIZ, "%s| %s",
70 "stub time", //debugLogTime(squid_curtime),
71 format);
72
73 _db_print_stderr(f, args2);
74
75 va_end(args1);
76 va_end(args2);
77 va_end(args3);
78}
79
80static void
81_db_print_stderr(const char *format, va_list args)
82{
25f98340
AJ
83 if (1 < Debug::level)
84 return;
85
86 vfprintf(stderr, format, args);
87}
88
bfa09779
AJ
89Debug::OutStream *Debug::CurrentDebug(NULL);
90
25f98340
AJ
91std::ostream &
92Debug::getDebugOut()
93{
94 assert(TheDepth >= 0);
95 ++TheDepth;
96 if (TheDepth > 1) {
97 assert(CurrentDebug);
98 *CurrentDebug << std::endl << "reentrant debuging " << TheDepth << "-{";
99 } else {
100 assert(!CurrentDebug);
bfa09779 101 CurrentDebug = new Debug::OutStream;
25f98340
AJ
102 // set default formatting flags
103 CurrentDebug->setf(std::ios::fixed);
104 CurrentDebug->precision(2);
105 }
106 return *CurrentDebug;
107}
108
109void
110Debug::parseOptions(char const *)
ced8def3 111{}
25f98340
AJ
112
113void
114Debug::finishDebug()
115{
116 assert(TheDepth >= 0);
117 assert(CurrentDebug);
118 if (TheDepth > 1) {
119 *CurrentDebug << "}-" << TheDepth << std::endl;
120 } else {
121 assert(TheDepth == 1);
122 _db_print("%s\n", CurrentDebug->str().c_str());
123 delete CurrentDebug;
124 CurrentDebug = NULL;
125 }
126 --TheDepth;
127}
128
129void
130Debug::xassert(const char *msg, const char *file, int line)
131{
25f98340
AJ
132 if (CurrentDebug) {
133 *CurrentDebug << "assertion failed: " << file << ":" << line <<
f53969cc 134 ": \"" << msg << "\"";
25f98340
AJ
135 }
136 abort();
137}
138
25f98340
AJ
139const char*
140SkipBuildPrefix(const char* path)
141{
142 return path;
143}
be039a68
AR
144
145std::ostream &
146Raw::print(std::ostream &os) const
147{
148 if (label_)
149 os << ' ' << label_ << '[' << size_ << ']';
150
151 if (!size_)
152 return os;
153
154 // finalize debugging level if no level was set explicitly via minLevel()
155 const int finalLevel = (level >= 0) ? level :
2113e038 156 (size_ > 40 ? DBG_DATA : Debug::sectionLevel);
be039a68
AR
157 if (finalLevel <= Debug::sectionLevel) {
158 os << (label_ ? '=' : ' ');
159 os.write(data_, size_);
160 }
161
162 return os;
163}
f53969cc 164