]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/stub_debug.cc
d6904a653c7a19bc22ade7040e05a346e098a693
[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
21 char *Debug::debugOptions;
22 char *Debug::cache_log= NULL;
23 int Debug::rotateNumber = 0;
24 int Debug::Levels[MAX_DEBUG_SECTIONS];
25 int Debug::override_X = 0;
26 int Debug::log_stderr = 1;
27 bool Debug::log_syslog = false;
28
29 Ctx
30 ctx_enter(const char *)
31 {
32 return -1;
33 }
34
35 void
36 ctx_exit(Ctx)
37 {}
38
39 void
40 _db_init(const char *, const char *)
41 {}
42
43 void
44 _db_set_syslog(const char *)
45 {}
46
47 void
48 _db_rotate_log(void)
49 {}
50
51 static void
52 _db_print_stderr(const char *format, va_list args);
53
54 void
55 _db_print(const char *format,...)
56 {
57 static char f[BUFSIZ];
58 va_list args1;
59 va_list args2;
60 va_list args3;
61
62 va_start(args1, format);
63 va_start(args2, format);
64 va_start(args3, format);
65
66 snprintf(f, BUFSIZ, "%s| %s",
67 "stub time", //debugLogTime(squid_curtime),
68 format);
69
70 _db_print_stderr(f, args2);
71
72 va_end(args1);
73 va_end(args2);
74 va_end(args3);
75 }
76
77 static void
78 _db_print_stderr(const char *format, va_list args)
79 {
80 if (1 < Debug::Level())
81 return;
82
83 vfprintf(stderr, format, args);
84 }
85
86 void
87 Debug::parseOptions(char const *)
88 {}
89
90 const char*
91 SkipBuildPrefix(const char* path)
92 {
93 return path;
94 }
95
96 Debug::Context *Debug::Current = nullptr;
97
98 Debug::Context::Context(const int aSection, const int aLevel):
99 level(aLevel),
100 sectionLevel(Levels[aSection]),
101 upper(Current)
102 {
103 buf.setf(std::ios::fixed);
104 buf.precision(2);
105 }
106
107 std::ostringstream &
108 Debug::Start(const int section, const int level)
109 {
110 Current = new Context(section, level);
111 return Current->buf;
112 }
113
114 void
115 Debug::Finish()
116 {
117 if (Current) {
118 _db_print("%s\n", Current->buf.str().c_str());
119 delete Current;
120 Current = nullptr;
121 }
122 }
123
124 std::ostream &
125 Raw::print(std::ostream &os) const
126 {
127 if (label_)
128 os << ' ' << label_ << '[' << size_ << ']';
129
130 if (!size_)
131 return os;
132
133 // finalize debugging level if no level was set explicitly via minLevel()
134 const int finalLevel = (level >= 0) ? level :
135 (size_ > 40 ? DBG_DATA : Debug::SectionLevel());
136 if (finalLevel <= Debug::SectionLevel()) {
137 os << (label_ ? '=' : ' ');
138 if (data_)
139 os.write(data_, size_);
140 else
141 os << "[null]";
142 }
143
144 return os;
145 }
146