]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/stub_debug.cc
merge from trunk r14590
[thirdparty/squid.git] / src / tests / stub_debug.cc
1 /*
2 * Copyright (C) 1996-2016 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 if (!CurrentDebug) {
95 CurrentDebug = new Debug::OutStream;
96 CurrentDebug->setf(std::ios::fixed);
97 CurrentDebug->precision(2);
98 }
99 return *CurrentDebug;
100 }
101
102 void
103 Debug::parseOptions(char const *)
104 {}
105
106 void
107 Debug::finishDebug()
108 {
109 std::cerr << "debugs: " << CurrentDebug->str() << std::endl;
110 delete CurrentDebug;
111 CurrentDebug = NULL;
112 }
113
114 void
115 Debug::xassert(const char *msg, const char *file, int line)
116 {
117 getDebugOut() << "assertion failed: " << file << ":" << line <<
118 ": \"" << msg << "\"";
119 abort();
120 }
121
122 const char*
123 SkipBuildPrefix(const char* path)
124 {
125 return path;
126 }
127
128 std::ostream &
129 Raw::print(std::ostream &os) const
130 {
131 if (label_)
132 os << ' ' << label_ << '[' << size_ << ']';
133
134 if (!size_)
135 return os;
136
137 // finalize debugging level if no level was set explicitly via minLevel()
138 const int finalLevel = (level >= 0) ? level :
139 (size_ > 40 ? DBG_DATA : Debug::sectionLevel);
140 if (finalLevel <= Debug::sectionLevel) {
141 os << (label_ ? '=' : ' ');
142 os.write(data_, size_);
143 }
144
145 return os;
146 }
147