]>
Commit | Line | Data |
---|---|---|
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 | 19 | FILE *debug_log = NULL; |
25f98340 AJ |
20 | |
21 | char *Debug::debugOptions; | |
22 | char *Debug::cache_log= NULL; | |
23 | int Debug::rotateNumber = 0; | |
24 | int Debug::Levels[MAX_DEBUG_SECTIONS]; | |
25f98340 AJ |
25 | int Debug::override_X = 0; |
26 | int Debug::log_stderr = 1; | |
27 | bool Debug::log_syslog = false; | |
28 | ||
29 | Ctx | |
ced8def3 | 30 | ctx_enter(const char *) |
25f98340 AJ |
31 | { |
32 | return -1; | |
33 | } | |
34 | ||
35 | void | |
ced8def3 AJ |
36 | ctx_exit(Ctx) |
37 | {} | |
25f98340 AJ |
38 | |
39 | void | |
ced8def3 | 40 | _db_init(const char *, const char *) |
25f98340 AJ |
41 | {} |
42 | ||
43 | void | |
ced8def3 | 44 | _db_set_syslog(const char *) |
25f98340 AJ |
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 | { | |
014adac1 | 80 | if (1 < Debug::Level()) |
25f98340 AJ |
81 | return; |
82 | ||
83 | vfprintf(stderr, format, args); | |
84 | } | |
85 | ||
014adac1 AR |
86 | void |
87 | Debug::parseOptions(char const *) | |
88 | {} | |
bfa09779 | 89 | |
014adac1 AR |
90 | const char* |
91 | SkipBuildPrefix(const char* path) | |
25f98340 | 92 | { |
014adac1 | 93 | return path; |
25f98340 AJ |
94 | } |
95 | ||
014adac1 | 96 | Debug::Context *Debug::Current = nullptr; |
25f98340 | 97 | |
014adac1 AR |
98 | Debug::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 |
107 | std::ostringstream & |
108 | Debug::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 |
114 | void |
115 | Debug::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 | |
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 : | |
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 |