]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/stub_debug.cc
Bug 3038: Detatch libmisc from libcompat
[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 #include "config.h"
6 #include "Debug.h"
7
8 #if HAVE_STDIO_H
9 #include <stdio.h>
10 #endif
11
12 FILE *debug_log = NULL;
13 int Debug::TheDepth = 0;
14
15 char *Debug::debugOptions;
16 char *Debug::cache_log= NULL;
17 int Debug::rotateNumber = 0;
18 int Debug::Levels[MAX_DEBUG_SECTIONS];
19 int Debug::level;
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 /* FIXME? */
77 // if (opt_debug_stderr < Debug::level)
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 }