]> git.ipfire.org Git - thirdparty/squid.git/blame - src/tests/stub_debug.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / tests / stub_debug.cc
CommitLineData
4e0938ef 1/*
f70aedc4 2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
4e0938ef
AJ
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
25f98340
AJ
9/*
10 * A stub implementation of the Debug.h API.
11 * For use by test binaries which do not need the full context debugging
54311b70
FC
12 *
13 * Note: it doesn't use the STUB API as the functions defined here must
14 * not abort the unit test.
25f98340 15 */
f7f3304a 16#include "squid.h"
25f98340
AJ
17#include "Debug.h"
18
0c7e529e
AR
19#define STUB_API "debug.cc"
20#include "tests/STUB.h"
25f98340
AJ
21
22char *Debug::debugOptions;
23char *Debug::cache_log= NULL;
24int Debug::rotateNumber = 0;
25int Debug::Levels[MAX_DEBUG_SECTIONS];
25f98340
AJ
26int Debug::override_X = 0;
27int Debug::log_stderr = 1;
28bool Debug::log_syslog = false;
e863656d 29void Debug::ForceAlert() STUB
25f98340 30
0c7e529e
AR
31void StopUsingDebugLog() STUB
32void ResyncDebugLog(FILE *) STUB
33
34FILE *
35DebugStream()
36{
37 return stderr;
38}
39
25f98340 40Ctx
ced8def3 41ctx_enter(const char *)
25f98340
AJ
42{
43 return -1;
44}
45
46void
ced8def3
AJ
47ctx_exit(Ctx)
48{}
25f98340
AJ
49
50void
ced8def3 51_db_init(const char *, const char *)
25f98340
AJ
52{}
53
54void
ced8def3 55_db_set_syslog(const char *)
25f98340
AJ
56{}
57
58void
59_db_rotate_log(void)
60{}
61
62static void
63_db_print_stderr(const char *format, va_list args);
64
65void
66_db_print(const char *format,...)
67{
68 static char f[BUFSIZ];
69 va_list args1;
70 va_list args2;
71 va_list args3;
72
73 va_start(args1, format);
74 va_start(args2, format);
75 va_start(args3, format);
76
77 snprintf(f, BUFSIZ, "%s| %s",
78 "stub time", //debugLogTime(squid_curtime),
79 format);
80
81 _db_print_stderr(f, args2);
82
83 va_end(args1);
84 va_end(args2);
85 va_end(args3);
86}
87
88static void
89_db_print_stderr(const char *format, va_list args)
90{
014adac1 91 if (1 < Debug::Level())
25f98340
AJ
92 return;
93
94 vfprintf(stderr, format, args);
95}
96
014adac1
AR
97void
98Debug::parseOptions(char const *)
99{}
bfa09779 100
014adac1 101Debug::Context *Debug::Current = nullptr;
25f98340 102
014adac1
AR
103Debug::Context::Context(const int aSection, const int aLevel):
104 level(aLevel),
105 sectionLevel(Levels[aSection]),
caf785dc
AR
106 upper(Current),
107 forceAlert(false)
25f98340 108{
014adac1
AR
109 buf.setf(std::ios::fixed);
110 buf.precision(2);
25f98340
AJ
111}
112
014adac1
AR
113std::ostringstream &
114Debug::Start(const int section, const int level)
25f98340 115{
014adac1
AR
116 Current = new Context(section, level);
117 return Current->buf;
25f98340
AJ
118}
119
014adac1
AR
120void
121Debug::Finish()
25f98340 122{
014adac1
AR
123 if (Current) {
124 _db_print("%s\n", Current->buf.str().c_str());
125 delete Current;
126 Current = nullptr;
127 }
25f98340 128}
be039a68 129
e863656d
CT
130std::ostream&
131ForceAlert(std::ostream& s)
132{
133 return s;
134}
135
be039a68
AR
136std::ostream &
137Raw::print(std::ostream &os) const
138{
139 if (label_)
140 os << ' ' << label_ << '[' << size_ << ']';
141
142 if (!size_)
143 return os;
144
145 // finalize debugging level if no level was set explicitly via minLevel()
146 const int finalLevel = (level >= 0) ? level :
014adac1
AR
147 (size_ > 40 ? DBG_DATA : Debug::SectionLevel());
148 if (finalLevel <= Debug::SectionLevel()) {
be039a68 149 os << (label_ ? '=' : ' ');
014adac1
AR
150 if (data_)
151 os.write(data_, size_);
152 else
153 os << "[null]";
be039a68
AR
154 }
155
156 return os;
157}
f53969cc 158