]>
Commit | Line | Data |
---|---|---|
4e0938ef | 1 | /* |
bde978a6 | 2 | * Copyright (C) 1996-2015 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 AJ |
19 | FILE *debug_log = NULL; |
20 | int Debug::TheDepth = 0; | |
21 | ||
22 | char *Debug::debugOptions; | |
23 | char *Debug::cache_log= NULL; | |
24 | int Debug::rotateNumber = 0; | |
25 | int Debug::Levels[MAX_DEBUG_SECTIONS]; | |
26 | int Debug::level; | |
be039a68 | 27 | int Debug::sectionLevel; |
25f98340 AJ |
28 | int Debug::override_X = 0; |
29 | int Debug::log_stderr = 1; | |
30 | bool Debug::log_syslog = false; | |
31 | ||
32 | Ctx | |
ced8def3 | 33 | ctx_enter(const char *) |
25f98340 AJ |
34 | { |
35 | return -1; | |
36 | } | |
37 | ||
38 | void | |
ced8def3 AJ |
39 | ctx_exit(Ctx) |
40 | {} | |
25f98340 AJ |
41 | |
42 | void | |
ced8def3 | 43 | _db_init(const char *, const char *) |
25f98340 AJ |
44 | {} |
45 | ||
46 | void | |
ced8def3 | 47 | _db_set_syslog(const char *) |
25f98340 AJ |
48 | {} |
49 | ||
50 | void | |
51 | _db_rotate_log(void) | |
52 | {} | |
53 | ||
54 | static void | |
55 | _db_print_stderr(const char *format, va_list args); | |
56 | ||
57 | void | |
58 | _db_print(const char *format,...) | |
59 | { | |
60 | static char f[BUFSIZ]; | |
61 | va_list args1; | |
62 | va_list args2; | |
63 | va_list args3; | |
64 | ||
65 | va_start(args1, format); | |
66 | va_start(args2, format); | |
67 | va_start(args3, format); | |
68 | ||
69 | snprintf(f, BUFSIZ, "%s| %s", | |
70 | "stub time", //debugLogTime(squid_curtime), | |
71 | format); | |
72 | ||
73 | _db_print_stderr(f, args2); | |
74 | ||
75 | va_end(args1); | |
76 | va_end(args2); | |
77 | va_end(args3); | |
78 | } | |
79 | ||
80 | static void | |
81 | _db_print_stderr(const char *format, va_list args) | |
82 | { | |
25f98340 AJ |
83 | if (1 < Debug::level) |
84 | return; | |
85 | ||
86 | vfprintf(stderr, format, args); | |
87 | } | |
88 | ||
bfa09779 AJ |
89 | Debug::OutStream *Debug::CurrentDebug(NULL); |
90 | ||
25f98340 AJ |
91 | std::ostream & |
92 | Debug::getDebugOut() | |
93 | { | |
94 | assert(TheDepth >= 0); | |
95 | ++TheDepth; | |
96 | if (TheDepth > 1) { | |
97 | assert(CurrentDebug); | |
98 | *CurrentDebug << std::endl << "reentrant debuging " << TheDepth << "-{"; | |
99 | } else { | |
100 | assert(!CurrentDebug); | |
bfa09779 | 101 | CurrentDebug = new Debug::OutStream; |
25f98340 AJ |
102 | // set default formatting flags |
103 | CurrentDebug->setf(std::ios::fixed); | |
104 | CurrentDebug->precision(2); | |
105 | } | |
106 | return *CurrentDebug; | |
107 | } | |
108 | ||
109 | void | |
110 | Debug::parseOptions(char const *) | |
ced8def3 | 111 | {} |
25f98340 AJ |
112 | |
113 | void | |
114 | Debug::finishDebug() | |
115 | { | |
116 | assert(TheDepth >= 0); | |
117 | assert(CurrentDebug); | |
118 | if (TheDepth > 1) { | |
119 | *CurrentDebug << "}-" << TheDepth << std::endl; | |
120 | } else { | |
121 | assert(TheDepth == 1); | |
122 | _db_print("%s\n", CurrentDebug->str().c_str()); | |
123 | delete CurrentDebug; | |
124 | CurrentDebug = NULL; | |
125 | } | |
126 | --TheDepth; | |
127 | } | |
128 | ||
129 | void | |
130 | Debug::xassert(const char *msg, const char *file, int line) | |
131 | { | |
25f98340 AJ |
132 | if (CurrentDebug) { |
133 | *CurrentDebug << "assertion failed: " << file << ":" << line << | |
f53969cc | 134 | ": \"" << msg << "\""; |
25f98340 AJ |
135 | } |
136 | abort(); | |
137 | } | |
138 | ||
25f98340 AJ |
139 | const char* |
140 | SkipBuildPrefix(const char* path) | |
141 | { | |
142 | return path; | |
143 | } | |
be039a68 AR |
144 | |
145 | std::ostream & | |
146 | Raw::print(std::ostream &os) const | |
147 | { | |
148 | if (label_) | |
149 | os << ' ' << label_ << '[' << size_ << ']'; | |
150 | ||
151 | if (!size_) | |
152 | return os; | |
153 | ||
154 | // finalize debugging level if no level was set explicitly via minLevel() | |
155 | const int finalLevel = (level >= 0) ? level : | |
2113e038 | 156 | (size_ > 40 ? DBG_DATA : Debug::sectionLevel); |
be039a68 AR |
157 | if (finalLevel <= Debug::sectionLevel) { |
158 | os << (label_ ? '=' : ' '); | |
159 | os.write(data_, size_); | |
160 | } | |
161 | ||
162 | return os; | |
163 | } | |
f53969cc | 164 |