]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/stub_debug.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / tests / stub_debug.cc
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
9 /*
10 * A stub implementation of the Debug.h API.
11 * For use by test binaries which do not need the full context debugging
12 *
13 * Note: it doesn't use the STUB API as the functions defined here must
14 * not abort the unit test.
15 */
16 #include "squid.h"
17 #include "Debug.h"
18
19 FILE *debug_log = NULL;
20 int Debug::TheDepth = 0;
21
22 char *Debug::debugOptions;
23 char *Debug::cache_log= NULL;
24 int Debug::rotateNumber = 0;
25 int Debug::Levels[MAX_DEBUG_SECTIONS];
26 int Debug::level;
27 int Debug::sectionLevel;
28 int Debug::override_X = 0;
29 int Debug::log_stderr = 1;
30 bool Debug::log_syslog = false;
31
32 Ctx
33 ctx_enter(const char *descr)
34 {
35 return -1;
36 }
37
38 void
39 ctx_exit(Ctx ctx)
40 {
41 }
42
43 void
44 _db_init(const char *logfile, const char *options)
45 {}
46
47 void
48 _db_set_syslog(const char *facility)
49 {}
50
51 void
52 _db_rotate_log(void)
53 {}
54
55 static void
56 _db_print_stderr(const char *format, va_list args);
57
58 void
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
81 static void
82 _db_print_stderr(const char *format, va_list args)
83 {
84 if (1 < Debug::level)
85 return;
86
87 vfprintf(stderr, format, args);
88 }
89
90 Debug::OutStream *Debug::CurrentDebug(NULL);
91
92 std::ostream &
93 Debug::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);
102 CurrentDebug = new Debug::OutStream;
103 // set default formatting flags
104 CurrentDebug->setf(std::ios::fixed);
105 CurrentDebug->precision(2);
106 }
107 return *CurrentDebug;
108 }
109
110 void
111 Debug::parseOptions(char const *)
112 {
113 return;
114 }
115
116 void
117 Debug::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
132 void
133 Debug::xassert(const char *msg, const char *file, int line)
134 {
135
136 if (CurrentDebug) {
137 *CurrentDebug << "assertion failed: " << file << ":" << line <<
138 ": \"" << msg << "\"";
139 }
140 abort();
141 }
142
143 const char*
144 SkipBuildPrefix(const char* path)
145 {
146 return path;
147 }
148
149 std::ostream &
150 Raw::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 :
160 (size_ > 40 ? DBG_DATA : Debug::sectionLevel);
161 if (finalLevel <= Debug::sectionLevel) {
162 os << (label_ ? '=' : ' ');
163 os.write(data_, size_);
164 }
165
166 return os;
167 }
168