]> git.ipfire.org Git - thirdparty/squid.git/blame - src/tests/stub_debug.cc
Bug 4748: r15240 broke IP-based URLs, twice. (#41)
[thirdparty/squid.git] / src / tests / stub_debug.cc
CommitLineData
4e0938ef 1/*
4ac4a490 2 * Copyright (C) 1996-2017 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
25f98340 19FILE *debug_log = NULL;
25f98340
AJ
20
21char *Debug::debugOptions;
22char *Debug::cache_log= NULL;
23int Debug::rotateNumber = 0;
24int Debug::Levels[MAX_DEBUG_SECTIONS];
25f98340
AJ
25int Debug::override_X = 0;
26int Debug::log_stderr = 1;
27bool Debug::log_syslog = false;
28
29Ctx
ced8def3 30ctx_enter(const char *)
25f98340
AJ
31{
32 return -1;
33}
34
35void
ced8def3
AJ
36ctx_exit(Ctx)
37{}
25f98340
AJ
38
39void
ced8def3 40_db_init(const char *, const char *)
25f98340
AJ
41{}
42
43void
ced8def3 44_db_set_syslog(const char *)
25f98340
AJ
45{}
46
47void
48_db_rotate_log(void)
49{}
50
51static void
52_db_print_stderr(const char *format, va_list args);
53
54void
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
77static void
78_db_print_stderr(const char *format, va_list args)
79{
014adac1 80 if (1 < Debug::Level())
25f98340
AJ
81 return;
82
83 vfprintf(stderr, format, args);
84}
85
014adac1
AR
86void
87Debug::parseOptions(char const *)
88{}
bfa09779 89
014adac1
AR
90const char*
91SkipBuildPrefix(const char* path)
25f98340 92{
014adac1 93 return path;
25f98340
AJ
94}
95
014adac1 96Debug::Context *Debug::Current = nullptr;
25f98340 97
014adac1
AR
98Debug::Context::Context(const int aSection, const int aLevel):
99 level(aLevel),
100 sectionLevel(Levels[aSection]),
101 upper(Current)
25f98340 102{
014adac1
AR
103 buf.setf(std::ios::fixed);
104 buf.precision(2);
25f98340
AJ
105}
106
014adac1
AR
107std::ostringstream &
108Debug::Start(const int section, const int level)
25f98340 109{
014adac1
AR
110 Current = new Context(section, level);
111 return Current->buf;
25f98340
AJ
112}
113
014adac1
AR
114void
115Debug::Finish()
25f98340 116{
014adac1
AR
117 if (Current) {
118 _db_print("%s\n", Current->buf.str().c_str());
119 delete Current;
120 Current = nullptr;
121 }
25f98340 122}
be039a68
AR
123
124std::ostream &
125Raw::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 :
014adac1
AR
135 (size_ > 40 ? DBG_DATA : Debug::SectionLevel());
136 if (finalLevel <= Debug::SectionLevel()) {
be039a68 137 os << (label_ ? '=' : ' ');
014adac1
AR
138 if (data_)
139 os.write(data_, size_);
140 else
141 os << "[null]";
be039a68
AR
142 }
143
144 return os;
145}
f53969cc 146