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