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