]>
Commit | Line | Data |
---|---|---|
4e0938ef | 1 | /* |
1f7b830e | 2 | * Copyright (C) 1996-2025 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" |
675b8408 | 17 | #include "debug/Stream.h" |
25f98340 | 18 | |
675b8408 | 19 | #define STUB_API "debug/libdebug.la" |
0c7e529e | 20 | #include "tests/STUB.h" |
25f98340 AJ |
21 | |
22 | char *Debug::debugOptions; | |
aee3523a | 23 | char *Debug::cache_log= nullptr; |
25f98340 AJ |
24 | int Debug::rotateNumber = 0; |
25 | int Debug::Levels[MAX_DEBUG_SECTIONS]; | |
25f98340 | 26 | int Debug::override_X = 0; |
25f98340 | 27 | bool Debug::log_syslog = false; |
e863656d | 28 | void Debug::ForceAlert() STUB |
25f98340 | 29 | |
0c7e529e AR |
30 | void ResyncDebugLog(FILE *) STUB |
31 | ||
32 | FILE * | |
33 | DebugStream() | |
34 | { | |
35 | return stderr; | |
36 | } | |
37 | ||
25f98340 AJ |
38 | void |
39 | _db_rotate_log(void) | |
40 | {} | |
41 | ||
b3f7a428 AR |
42 | void |
43 | Debug::FormatStream(std::ostream &buf) | |
44 | { | |
45 | const static std::ostringstream cleanStream; | |
46 | buf.flags(cleanStream.flags() | std::ios::fixed); | |
47 | buf.width(cleanStream.width()); | |
48 | buf.precision(2); | |
49 | buf.fill(' '); | |
50 | } | |
51 | ||
61be1d8e AR |
52 | void |
53 | Debug::LogMessage(const Context &context) | |
25f98340 | 54 | { |
61be1d8e AR |
55 | if (context.level > DBG_IMPORTANT) |
56 | return; | |
25f98340 | 57 | |
61be1d8e | 58 | if (!stderr) |
25f98340 AJ |
59 | return; |
60 | ||
61be1d8e | 61 | fprintf(stderr, "%s| %s\n", |
57e7bd57 | 62 | "stub time", // debugLogTime(current_time), |
61be1d8e | 63 | context.buf.str().c_str()); |
25f98340 AJ |
64 | } |
65 | ||
b3f7a428 AR |
66 | std::ostream & |
67 | Debug::Extra(std::ostream &os) | |
68 | { | |
69 | FormatStream(os); | |
70 | os << "\n "; | |
71 | return os; | |
72 | } | |
73 | ||
61be1d8e AR |
74 | bool Debug::StderrEnabled() STUB_RETVAL(false) |
75 | void Debug::PrepareToDie() STUB | |
76 | ||
014adac1 AR |
77 | void |
78 | Debug::parseOptions(char const *) | |
79 | {} | |
bfa09779 | 80 | |
014adac1 | 81 | Debug::Context *Debug::Current = nullptr; |
25f98340 | 82 | |
014adac1 | 83 | Debug::Context::Context(const int aSection, const int aLevel): |
61be1d8e | 84 | section(aSection), |
014adac1 AR |
85 | level(aLevel), |
86 | sectionLevel(Levels[aSection]), | |
caf785dc AR |
87 | upper(Current), |
88 | forceAlert(false) | |
25f98340 | 89 | { |
b3f7a428 | 90 | FormatStream(buf); |
25f98340 AJ |
91 | } |
92 | ||
014adac1 AR |
93 | std::ostringstream & |
94 | Debug::Start(const int section, const int level) | |
25f98340 | 95 | { |
014adac1 AR |
96 | Current = new Context(section, level); |
97 | return Current->buf; | |
25f98340 AJ |
98 | } |
99 | ||
014adac1 AR |
100 | void |
101 | Debug::Finish() | |
25f98340 | 102 | { |
014adac1 | 103 | if (Current) { |
61be1d8e | 104 | LogMessage(*Current); |
014adac1 AR |
105 | delete Current; |
106 | Current = nullptr; | |
107 | } | |
25f98340 | 108 | } |
be039a68 | 109 | |
e863656d CT |
110 | std::ostream& |
111 | ForceAlert(std::ostream& s) | |
112 | { | |
113 | return s; | |
114 | } | |
115 |