]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/stub_debug.cc
Merged from trunk
[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 #if HAVE_STDIO_H
12 #include <stdio.h>
13 #endif
14
15 FILE *debug_log = NULL;
16 int Debug::TheDepth = 0;
17
18 char *Debug::debugOptions;
19 char *Debug::cache_log= NULL;
20 int Debug::rotateNumber = 0;
21 int Debug::Levels[MAX_DEBUG_SECTIONS];
22 int Debug::level;
23 int Debug::override_X = 0;
24 int Debug::log_stderr = 1;
25 bool Debug::log_syslog = false;
26
27 Ctx
28 ctx_enter(const char *descr)
29 {
30 return -1;
31 }
32
33 void
34 ctx_exit(Ctx ctx)
35 {
36 }
37
38 void
39 _db_init(const char *logfile, const char *options)
40 {}
41
42 void
43 _db_set_syslog(const char *facility)
44 {}
45
46 void
47 _db_rotate_log(void)
48 {}
49
50 static void
51 _db_print_stderr(const char *format, va_list args);
52
53 void
54 _db_print(const char *format,...)
55 {
56 static char f[BUFSIZ];
57 va_list args1;
58 va_list args2;
59 va_list args3;
60
61 va_start(args1, format);
62 va_start(args2, format);
63 va_start(args3, format);
64
65 snprintf(f, BUFSIZ, "%s| %s",
66 "stub time", //debugLogTime(squid_curtime),
67 format);
68
69 _db_print_stderr(f, args2);
70
71 va_end(args1);
72 va_end(args2);
73 va_end(args3);
74 }
75
76 static void
77 _db_print_stderr(const char *format, va_list args)
78 {
79 if (1 < Debug::level)
80 return;
81
82 vfprintf(stderr, format, args);
83 }
84
85 std::ostream &
86 Debug::getDebugOut()
87 {
88 assert(TheDepth >= 0);
89 ++TheDepth;
90 if (TheDepth > 1) {
91 assert(CurrentDebug);
92 *CurrentDebug << std::endl << "reentrant debuging " << TheDepth << "-{";
93 } else {
94 assert(!CurrentDebug);
95 CurrentDebug = new std::ostringstream();
96 // set default formatting flags
97 CurrentDebug->setf(std::ios::fixed);
98 CurrentDebug->precision(2);
99 }
100 return *CurrentDebug;
101 }
102
103 void
104 Debug::parseOptions(char const *)
105 {
106 return;
107 }
108
109 void
110 Debug::finishDebug()
111 {
112 assert(TheDepth >= 0);
113 assert(CurrentDebug);
114 if (TheDepth > 1) {
115 *CurrentDebug << "}-" << TheDepth << std::endl;
116 } else {
117 assert(TheDepth == 1);
118 _db_print("%s\n", CurrentDebug->str().c_str());
119 delete CurrentDebug;
120 CurrentDebug = NULL;
121 }
122 --TheDepth;
123 }
124
125 void
126 Debug::xassert(const char *msg, const char *file, int line)
127 {
128
129 if (CurrentDebug) {
130 *CurrentDebug << "assertion failed: " << file << ":" << line <<
131 ": \"" << msg << "\"";
132 }
133 abort();
134 }
135
136 std::ostringstream *Debug::CurrentDebug (NULL);
137
138 const char*
139 SkipBuildPrefix(const char* path)
140 {
141 return path;
142 }