]>
Commit | Line | Data |
---|---|---|
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 | |
22 | char *Debug::debugOptions; | |
23 | char *Debug::cache_log= NULL; | |
24 | int Debug::rotateNumber = 0; | |
25 | int Debug::Levels[MAX_DEBUG_SECTIONS]; | |
25f98340 AJ |
26 | int Debug::override_X = 0; |
27 | int Debug::log_stderr = 1; | |
28 | bool Debug::log_syslog = false; | |
e863656d | 29 | void Debug::ForceAlert() STUB |
25f98340 | 30 | |
0c7e529e AR |
31 | void StopUsingDebugLog() STUB |
32 | void ResyncDebugLog(FILE *) STUB | |
33 | ||
34 | FILE * | |
35 | DebugStream() | |
36 | { | |
37 | return stderr; | |
38 | } | |
39 | ||
25f98340 | 40 | Ctx |
ced8def3 | 41 | ctx_enter(const char *) |
25f98340 AJ |
42 | { |
43 | return -1; | |
44 | } | |
45 | ||
46 | void | |
ced8def3 AJ |
47 | ctx_exit(Ctx) |
48 | {} | |
25f98340 AJ |
49 | |
50 | void | |
ced8def3 | 51 | _db_init(const char *, const char *) |
25f98340 AJ |
52 | {} |
53 | ||
54 | void | |
ced8def3 | 55 | _db_set_syslog(const char *) |
25f98340 AJ |
56 | {} |
57 | ||
58 | void | |
59 | _db_rotate_log(void) | |
60 | {} | |
61 | ||
62 | static void | |
63 | _db_print_stderr(const char *format, va_list args); | |
64 | ||
65 | void | |
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 | ||
88 | static 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 |
97 | void |
98 | Debug::parseOptions(char const *) | |
99 | {} | |
bfa09779 | 100 | |
014adac1 | 101 | Debug::Context *Debug::Current = nullptr; |
25f98340 | 102 | |
014adac1 AR |
103 | Debug::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 |
113 | std::ostringstream & |
114 | Debug::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 |
120 | void |
121 | Debug::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 |
130 | std::ostream& |
131 | ForceAlert(std::ostream& s) | |
132 | { | |
133 | return s; | |
134 | } | |
135 | ||
be039a68 AR |
136 | std::ostream & |
137 | Raw::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 |