]> 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-2015 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 *)
34 {
35 return -1;
36 }
37
38 void
39 ctx_exit(Ctx)
40 {}
41
42 void
43 _db_init(const char *, const char *)
44 {}
45
46 void
47 _db_set_syslog(const char *)
48 {}
49
50 void
51 _db_rotate_log(void)
52 {}
53
54 static void
55 _db_print_stderr(const char *format, va_list args);
56
57 void
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
80 static void
81 _db_print_stderr(const char *format, va_list args)
82 {
83 if (1 < Debug::level)
84 return;
85
86 vfprintf(stderr, format, args);
87 }
88
89 Debug::OutStream *Debug::CurrentDebug(NULL);
90
91 std::ostream &
92 Debug::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);
101 CurrentDebug = new Debug::OutStream;
102 // set default formatting flags
103 CurrentDebug->setf(std::ios::fixed);
104 CurrentDebug->precision(2);
105 }
106 return *CurrentDebug;
107 }
108
109 void
110 Debug::parseOptions(char const *)
111 {}
112
113 void
114 Debug::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
129 void
130 Debug::xassert(const char *msg, const char *file, int line)
131 {
132 if (CurrentDebug) {
133 *CurrentDebug << "assertion failed: " << file << ":" << line <<
134 ": \"" << msg << "\"";
135 }
136 abort();
137 }
138
139 const char*
140 SkipBuildPrefix(const char* path)
141 {
142 return path;
143 }
144
145 std::ostream &
146 Raw::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 :
156 (size_ > 40 ? DBG_DATA : Debug::sectionLevel);
157 if (finalLevel <= Debug::sectionLevel) {
158 os << (label_ ? '=' : ' ');
159 os.write(data_, size_);
160 }
161
162 return os;
163 }
164