]> 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
AJ
1/*
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
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
33ctx_enter(const char *descr)
34{
35 return -1;
36}
37
38void
39ctx_exit(Ctx ctx)
40{
41}
42
43void
44_db_init(const char *logfile, const char *options)
45{}
46
47void
48_db_set_syslog(const char *facility)
49{}
50
51void
52_db_rotate_log(void)
53{}
54
55static void
56_db_print_stderr(const char *format, va_list args);
57
58void
59_db_print(const char *format,...)
60{
61 static char f[BUFSIZ];
62 va_list args1;
63 va_list args2;
64 va_list args3;
65
66 va_start(args1, format);
67 va_start(args2, format);
68 va_start(args3, format);
69
70 snprintf(f, BUFSIZ, "%s| %s",
71 "stub time", //debugLogTime(squid_curtime),
72 format);
73
74 _db_print_stderr(f, args2);
75
76 va_end(args1);
77 va_end(args2);
78 va_end(args3);
79}
80
81static void
82_db_print_stderr(const char *format, va_list args)
83{
25f98340
AJ
84 if (1 < Debug::level)
85 return;
86
87 vfprintf(stderr, format, args);
88}
89
bfa09779
AJ
90Debug::OutStream *Debug::CurrentDebug(NULL);
91
25f98340
AJ
92std::ostream &
93Debug::getDebugOut()
94{
95 assert(TheDepth >= 0);
96 ++TheDepth;
97 if (TheDepth > 1) {
98 assert(CurrentDebug);
99 *CurrentDebug << std::endl << "reentrant debuging " << TheDepth << "-{";
100 } else {
101 assert(!CurrentDebug);
bfa09779 102 CurrentDebug = new Debug::OutStream;
25f98340
AJ
103 // set default formatting flags
104 CurrentDebug->setf(std::ios::fixed);
105 CurrentDebug->precision(2);
106 }
107 return *CurrentDebug;
108}
109
110void
111Debug::parseOptions(char const *)
112{
113 return;
114}
115
116void
117Debug::finishDebug()
118{
119 assert(TheDepth >= 0);
120 assert(CurrentDebug);
121 if (TheDepth > 1) {
122 *CurrentDebug << "}-" << TheDepth << std::endl;
123 } else {
124 assert(TheDepth == 1);
125 _db_print("%s\n", CurrentDebug->str().c_str());
126 delete CurrentDebug;
127 CurrentDebug = NULL;
128 }
129 --TheDepth;
130}
131
132void
133Debug::xassert(const char *msg, const char *file, int line)
134{
135
136 if (CurrentDebug) {
137 *CurrentDebug << "assertion failed: " << file << ":" << line <<
f53969cc 138 ": \"" << msg << "\"";
25f98340
AJ
139 }
140 abort();
141}
142
25f98340
AJ
143const char*
144SkipBuildPrefix(const char* path)
145{
146 return path;
147}
be039a68
AR
148
149std::ostream &
150Raw::print(std::ostream &os) const
151{
152 if (label_)
153 os << ' ' << label_ << '[' << size_ << ']';
154
155 if (!size_)
156 return os;
157
158 // finalize debugging level if no level was set explicitly via minLevel()
159 const int finalLevel = (level >= 0) ? level :
2113e038 160 (size_ > 40 ? DBG_DATA : Debug::sectionLevel);
be039a68
AR
161 if (finalLevel <= Debug::sectionLevel) {
162 os << (label_ ? '=' : ' ');
163 os.write(data_, size_);
164 }
165
166 return os;
167}
f53969cc 168