/proc/self/cwd/base/logging.h
Line | Count | Source |
1 | | /* |
2 | | * Licensed to the Apache Software Foundation (ASF) under one |
3 | | * or more contributor license agreements. See the NOTICE file |
4 | | * distributed with this work for additional information |
5 | | * regarding copyright ownership. The ASF licenses this file |
6 | | * to you under the Apache License, Version 2.0 (the |
7 | | * "License"); you may not use this file except in compliance |
8 | | * with the License. You may obtain a copy of the License at |
9 | | * |
10 | | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | | * |
12 | | * Unless required by applicable law or agreed to in writing, |
13 | | * software distributed under the License is distributed on an |
14 | | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
15 | | * KIND, either express or implied. See the License for the |
16 | | * specific language governing permissions and limitations |
17 | | * under the License. |
18 | | */ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include <cstdlib> |
23 | | #include <memory> |
24 | | #include <sstream> |
25 | | #include <string> |
26 | | |
27 | | // Severity levels |
28 | | namespace logging { |
29 | | constexpr int LOG_INFO = 0; |
30 | | constexpr int LOG_WARNING = 1; |
31 | | constexpr int LOG_ERROR = 2; |
32 | | constexpr int LOG_FATAL = 3; |
33 | | // DFATAL = fatal in debug builds, error in release builds |
34 | | #ifdef NDEBUG |
35 | | constexpr int LOG_DFATAL = LOG_ERROR; |
36 | | #else |
37 | | constexpr int LOG_DFATAL = LOG_FATAL; |
38 | | #endif |
39 | | } // namespace logging |
40 | | |
41 | | namespace pagespeed_logging { |
42 | | |
43 | | // Log sink interface for redirecting log output (e.g., to Apache error log) |
44 | | class LogSink { |
45 | | public: |
46 | 0 | virtual ~LogSink() = default; |
47 | | virtual void send(int severity, const char* full_filename, |
48 | | const char* base_filename, int line, const char* message, |
49 | | size_t message_len) = 0; |
50 | | }; |
51 | | |
52 | | // Add/remove log sinks |
53 | | void AddLogSink(LogSink* sink); |
54 | | void RemoveLogSink(LogSink* sink); |
55 | | |
56 | | // Signal that the process is shutting down. After this call, LOG() writes |
57 | | // to stderr instead of spdlog, avoiding crashes from the static destruction |
58 | | // order fiasco (spdlog's global logger may already be destroyed). |
59 | | void ShutDownLogging(); |
60 | | |
61 | | // Internal: send to all registered sinks |
62 | | void SendToSinks(int severity, const char* full_filename, |
63 | | const char* base_filename, int line, const char* message, |
64 | | size_t message_len); |
65 | | |
66 | | // Log message stream that outputs on destruction |
67 | | class LogMessage { |
68 | | public: |
69 | | LogMessage(int severity, const char* file, int line) |
70 | 22.3M | : severity_(severity), file_(file), line_(line) {} |
71 | | |
72 | | ~LogMessage(); |
73 | | |
74 | 22.3M | std::ostream& stream() { return stream_; } |
75 | | |
76 | | private: |
77 | | int severity_; |
78 | | const char* file_; |
79 | | int line_; |
80 | | std::ostringstream stream_; |
81 | | }; |
82 | | |
83 | | // LogMessage that checks a condition |
84 | | class LogMessageVoidify { |
85 | | public: |
86 | 0 | void operator&(std::ostream&) {} |
87 | | }; |
88 | | |
89 | | // Extract base filename from full path |
90 | 22.3M | inline const char* GetBasename(const char* filepath) { |
91 | 22.3M | const char* base = filepath; |
92 | 1.16G | for (const char* p = filepath; *p; ++p) { |
93 | 1.14G | if (*p == '/' || *p == '\\') { |
94 | 117M | base = p + 1; |
95 | 117M | } |
96 | 1.14G | } |
97 | 22.3M | return base; |
98 | 22.3M | } |
99 | | |
100 | | // Check failure message - logs and aborts |
101 | | class CheckOpMessageBuilder { |
102 | | public: |
103 | | explicit CheckOpMessageBuilder(const char* exprtext) |
104 | 0 | : stream_(new std::ostringstream) { |
105 | 0 | *stream_ << "Check failed: " << exprtext << " "; |
106 | 0 | } |
107 | 0 | ~CheckOpMessageBuilder() { delete stream_; } |
108 | 0 | std::ostream& stream() { return *stream_; } |
109 | 0 | std::ostream* ForVar2() { |
110 | 0 | *stream_ << " vs. "; |
111 | 0 | return stream_; |
112 | 0 | } |
113 | 0 | std::string* NewString() { return new std::string(stream_->str()); } |
114 | | |
115 | | private: |
116 | | std::ostringstream* stream_; |
117 | | }; |
118 | | |
119 | | template <typename T1, typename T2> |
120 | 0 | std::string* MakeCheckOpString(const T1& v1, const T2& v2, const char* expr) { |
121 | 0 | CheckOpMessageBuilder builder(expr); |
122 | 0 | builder.stream() << v1; |
123 | 0 | *builder.ForVar2() << v2; |
124 | 0 | return builder.NewString(); |
125 | 0 | } Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::MakeCheckOpString<unsigned int, unsigned long>(unsigned int const&, unsigned long const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::MakeCheckOpString<int, net_instaweb::HtmlName::Keyword>(int const&, net_instaweb::HtmlName::Keyword const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::MakeCheckOpString<unsigned long, unsigned long>(unsigned long const&, unsigned long const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::MakeCheckOpString<net_instaweb::HtmlName::Keyword, net_instaweb::HtmlName::Keyword>(net_instaweb::HtmlName::Keyword const&, net_instaweb::HtmlName::Keyword const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::MakeCheckOpString<int, int>(int const&, int const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::MakeCheckOpString<net_instaweb::HtmlElement*, net_instaweb::HtmlElement*>(net_instaweb::HtmlElement* const&, net_instaweb::HtmlElement* const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::MakeCheckOpString<char, char>(char const&, char const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::MakeCheckOpString<char*, char*>(char* const&, char* const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::MakeCheckOpString<Css::SimpleSelector::Type, Css::SimpleSelector::Type>(Css::SimpleSelector::Type const&, Css::SimpleSelector::Type const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::MakeCheckOpString<Css::Ruleset::Type, Css::Ruleset::Type>(Css::Ruleset::Type const&, Css::Ruleset::Type const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::MakeCheckOpString<char const*, char const*>(char const* const&, char const* const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::MakeCheckOpString<Css::Identifier::Ident, Css::Identifier::Ident>(Css::Identifier::Ident const&, Css::Identifier::Ident const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::MakeCheckOpString<Css::Property::Prop, Css::Property::Prop>(Css::Property::Prop const&, Css::Property::Prop const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::MakeCheckOpString<Css::Value::Unit, Css::Value::Unit>(Css::Value::Unit const&, Css::Value::Unit const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::MakeCheckOpString<Css::Value::ValueType, Css::Value::ValueType>(Css::Value::ValueType const&, Css::Value::ValueType const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::MakeCheckOpString<pagespeed::js::JsTokenizer::ParseState, pagespeed::js::JsTokenizer::ParseState>(pagespeed::js::JsTokenizer::ParseState const&, pagespeed::js::JsTokenizer::ParseState const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::MakeCheckOpString<unsigned long, unsigned int>(unsigned long const&, unsigned int const&, char const*) |
126 | | |
127 | | // Check operation helpers |
128 | | #define DEFINE_CHECK_OP(name, op) \ |
129 | | template <typename T1, typename T2> \ |
130 | | inline std::string* Check##name##Impl(const T1& v1, const T2& v2, \ |
131 | 49.3M | const char* exprtext) { \ |
132 | 49.3M | if (v1 op v2) return nullptr; \ |
133 | 49.3M | return ::pagespeed_logging::MakeCheckOpString(v1, v2, exprtext); \ |
134 | 49.3M | } Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckLEImpl<unsigned int, unsigned long>(unsigned int const&, unsigned long const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckGEImpl<int, net_instaweb::HtmlName::Keyword>(int const&, net_instaweb::HtmlName::Keyword const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckLTImpl<unsigned long, unsigned long>(unsigned long const&, unsigned long const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckNEImpl<net_instaweb::HtmlName::Keyword, net_instaweb::HtmlName::Keyword>(net_instaweb::HtmlName::Keyword const&, net_instaweb::HtmlName::Keyword const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckEQImpl<int, int>(int const&, int const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckEQImpl<net_instaweb::HtmlElement*, net_instaweb::HtmlElement*>(net_instaweb::HtmlElement* const&, net_instaweb::HtmlElement* const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckEQImpl<char, char>(char const&, char const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckEQImpl<unsigned int, unsigned long>(unsigned int const&, unsigned long const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckEQImpl<unsigned long, unsigned long>(unsigned long const&, unsigned long const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckLTImpl<int, int>(int const&, int const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckLEImpl<unsigned long, unsigned long>(unsigned long const&, unsigned long const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckGEImpl<char*, char*>(char* const&, char* const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckEQImpl<Css::SimpleSelector::Type, Css::SimpleSelector::Type>(Css::SimpleSelector::Type const&, Css::SimpleSelector::Type const&, char const*) std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckEQImpl<Css::Ruleset::Type, Css::Ruleset::Type>(Css::Ruleset::Type const&, Css::Ruleset::Type const&, char const*) Line | Count | Source | 131 | 716k | const char* exprtext) { \ | 132 | 716k | if (v1 op v2) return nullptr; \ | 133 | 716k | return ::pagespeed_logging::MakeCheckOpString(v1, v2, exprtext); \ | 134 | 716k | } |
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckLEImpl<char const*, char const*>(char const* const&, char const* const&, char const*) Line | Count | Source | 131 | 48.6M | const char* exprtext) { \ | 132 | 48.6M | if (v1 op v2) return nullptr; \ | 133 | 48.6M | return ::pagespeed_logging::MakeCheckOpString(v1, v2, exprtext); \ | 134 | 48.6M | } |
Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckLTImpl<char const*, char const*>(char const* const&, char const* const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckLTImpl<Css::Identifier::Ident, Css::Identifier::Ident>(Css::Identifier::Ident const&, Css::Identifier::Ident const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckLTImpl<Css::Property::Prop, Css::Property::Prop>(Css::Property::Prop const&, Css::Property::Prop const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckNEImpl<Css::Value::Unit, Css::Value::Unit>(Css::Value::Unit const&, Css::Value::Unit const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckLTImpl<Css::Value::Unit, Css::Value::Unit>(Css::Value::Unit const&, Css::Value::Unit const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckEQImpl<Css::Value::ValueType, Css::Value::ValueType>(Css::Value::ValueType const&, Css::Value::ValueType const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckGEImpl<int, int>(int const&, int const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckGEImpl<char const*, char const*>(char const* const&, char const* const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckEQImpl<pagespeed::js::JsTokenizer::ParseState, pagespeed::js::JsTokenizer::ParseState>(pagespeed::js::JsTokenizer::ParseState const&, pagespeed::js::JsTokenizer::ParseState const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckGEImpl<unsigned long, unsigned int>(unsigned long const&, unsigned int const&, char const*) Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >* pagespeed_logging::CheckGTImpl<int, int>(int const&, int const&, char const*) |
135 | | |
136 | | DEFINE_CHECK_OP(EQ, ==) |
137 | | DEFINE_CHECK_OP(NE, !=) |
138 | | DEFINE_CHECK_OP(LT, <) |
139 | | DEFINE_CHECK_OP(LE, <=) |
140 | | DEFINE_CHECK_OP(GT, >) |
141 | | DEFINE_CHECK_OP(GE, >=) |
142 | | |
143 | | #undef DEFINE_CHECK_OP |
144 | | |
145 | | // Check failure class that logs on destruction and aborts for FATAL. |
146 | | // |
147 | | // The object is built on every CHECK evaluation, passing or not, so it must |
148 | | // not allocate on the passing path: the stream for text streamed onto a |
149 | | // failed check is created on first use, which only happens when the check |
150 | | // failed. (A std::ostringstream member costs a heap allocation per check |
151 | | // with some standard libraries.) |
152 | | class CheckOpResult { |
153 | | public: |
154 | | CheckOpResult(std::string* msg, const char* file, int line) |
155 | 49.3M | : msg_(msg), file_(file), line_(line) {} |
156 | 49.3M | ~CheckOpResult() { |
157 | 49.3M | if (msg_) { |
158 | 0 | ::pagespeed_logging::LogMessage(logging::LOG_FATAL, file_, line_).stream() |
159 | 0 | << *msg_ << (extra_stream_ ? extra_stream_->str() : std::string()); |
160 | 0 | delete msg_; |
161 | 0 | } |
162 | 49.3M | } |
163 | 49.3M | operator bool() const { return msg_ != nullptr; } |
164 | 0 | std::ostream& stream() { |
165 | 0 | if (!extra_stream_) extra_stream_ = std::make_unique<std::ostringstream>(); |
166 | 0 | return *extra_stream_; |
167 | 0 | } |
168 | | |
169 | | private: |
170 | | std::string* msg_; |
171 | | const char* file_; |
172 | | int line_; |
173 | | std::unique_ptr<std::ostringstream> extra_stream_; |
174 | | }; |
175 | | |
176 | | } // namespace pagespeed_logging |
177 | | |
178 | | // Main LOG macro |
179 | | #define LOG(severity) \ |
180 | 30.6M | ::pagespeed_logging::LogMessage(logging::LOG_##severity, __FILE__, __LINE__) \ |
181 | 30.6M | .stream() |
182 | | |
183 | | // VLOG - verbose logging. Verbose messages carry a negative severity |
184 | | // (-(verboselevel), the glog convention) so that log sinks can route them |
185 | | // to debug-level output instead of reporting them as info. They are not |
186 | | // written to any process logger (see LogMessage::~LogMessage); registered |
187 | | // sinks decide whether to keep them, e.g. the Apache module emits them |
188 | | // only when its LogLevel is debug. |
189 | | #define VLOG(verboselevel) \ |
190 | 32.4M | ::pagespeed_logging::LogMessage(-(verboselevel), __FILE__, __LINE__).stream() |
191 | | |
192 | | // VLOG_IS_ON - check if verbose logging is enabled at given level. |
193 | | // Always true: every verbose message reaches the sinks, which apply their |
194 | | // own level cutoffs. |
195 | | #define VLOG_IS_ON(verboselevel) (true) |
196 | | |
197 | | // LOG_IF - conditional logging |
198 | | // |
199 | | // The replacement list must stay unparenthesized: a trailing '<<' (as in |
200 | | // CHECK below) has to bind into the conditional so the message is built only |
201 | | // when the condition holds. Enclosing the list in parentheses makes the |
202 | | // expression void and breaks every 'LOG_IF(...) << msg' use. |
203 | | // NOLINTBEGIN(bugprone-macro-parentheses) |
204 | | #define LOG_IF(severity, condition) \ |
205 | 79.9k | !(condition) ? (void)0 \ |
206 | 79.9k | : ::pagespeed_logging::LogMessageVoidify() & \ |
207 | 0 | ::pagespeed_logging::LogMessage(logging::LOG_##severity, \ |
208 | 0 | __FILE__, __LINE__) \ |
209 | 0 | .stream() |
210 | | // NOLINTEND(bugprone-macro-parentheses) |
211 | | |
212 | | // DLOG - debug logging (compiles to nothing in release builds) |
213 | | #ifdef NDEBUG |
214 | | #define DLOG(severity) \ |
215 | 0 | true ? (void)0 \ |
216 | 0 | : ::pagespeed_logging::LogMessageVoidify() & \ |
217 | 0 | ::pagespeed_logging::LogMessage(logging::LOG_##severity, \ |
218 | 0 | __FILE__, __LINE__) \ |
219 | 0 | .stream() |
220 | | #define DVLOG(verboselevel) \ |
221 | | true ? (void)0 \ |
222 | | : ::pagespeed_logging::LogMessageVoidify() & \ |
223 | | ::pagespeed_logging::LogMessage(logging::LOG_INFO, __FILE__, \ |
224 | | __LINE__) \ |
225 | | .stream() |
226 | | #else |
227 | | #define DLOG(severity) LOG(severity) |
228 | | #define DVLOG(verboselevel) VLOG(verboselevel) |
229 | | #endif |
230 | | |
231 | | // Note: LOG(DFATAL) is handled via logging::LOG_DFATAL constexpr (see above). |
232 | | // DFATAL = fatal in debug builds, error in release builds. |
233 | | |
234 | | // CHECK macros - always active |
235 | | #define CHECK(condition) \ |
236 | 79.9k | LOG_IF(FATAL, !(condition)) << "Check failed: " #condition " " |
237 | | |
238 | | #define CHECK_OP(name, op, val1, val2) \ |
239 | 79.0M | if (::pagespeed_logging::CheckOpResult _result{ \ |
240 | 79.0M | ::pagespeed_logging::Check##name##Impl((val1), (val2), \ |
241 | 79.0M | #val1 " " #op " " #val2), \ |
242 | 79.0M | __FILE__, __LINE__}; \ |
243 | 79.0M | _result) \ |
244 | 79.0M | _result.stream() |
245 | | |
246 | 716k | #define CHECK_EQ(val1, val2) CHECK_OP(EQ, ==, val1, val2) |
247 | 0 | #define CHECK_NE(val1, val2) CHECK_OP(NE, !=, val1, val2) |
248 | 0 | #define CHECK_LT(val1, val2) CHECK_OP(LT, <, val1, val2) |
249 | 48.6M | #define CHECK_LE(val1, val2) CHECK_OP(LE, <=, val1, val2) |
250 | 0 | #define CHECK_GT(val1, val2) CHECK_OP(GT, >, val1, val2) |
251 | 0 | #define CHECK_GE(val1, val2) CHECK_OP(GE, >=, val1, val2) |
252 | | |
253 | | // DCHECK macros - only active in debug builds |
254 | | #ifdef NDEBUG |
255 | | #define DCHECK(condition) \ |
256 | 439M | while (false) CHECK(condition) |
257 | | #define DCHECK_EQ(val1, val2) \ |
258 | 50.7M | while (false) CHECK_EQ(val1, val2) |
259 | | #define DCHECK_NE(val1, val2) \ |
260 | 121k | while (false) CHECK_NE(val1, val2) |
261 | | #define DCHECK_LT(val1, val2) \ |
262 | 27.8M | while (false) CHECK_LT(val1, val2) |
263 | | #define DCHECK_LE(val1, val2) \ |
264 | 7.22M | while (false) CHECK_LE(val1, val2) |
265 | | #define DCHECK_GT(val1, val2) \ |
266 | 8.12M | while (false) CHECK_GT(val1, val2) |
267 | | #define DCHECK_GE(val1, val2) \ |
268 | 4.45M | while (false) CHECK_GE(val1, val2) |
269 | | #else |
270 | | #define DCHECK(condition) CHECK(condition) |
271 | | #define DCHECK_EQ(val1, val2) CHECK_EQ(val1, val2) |
272 | | #define DCHECK_NE(val1, val2) CHECK_NE(val1, val2) |
273 | | #define DCHECK_LT(val1, val2) CHECK_LT(val1, val2) |
274 | | #define DCHECK_LE(val1, val2) CHECK_LE(val1, val2) |
275 | | #define DCHECK_GT(val1, val2) CHECK_GT(val1, val2) |
276 | | #define DCHECK_GE(val1, val2) CHECK_GE(val1, val2) |
277 | | #endif |
278 | | |
279 | | // CHECK_NOTNULL - check that a pointer is not null and return it |
280 | | template <typename T> |
281 | | T* CheckNotNull(const char* file, int line, const char* expr, T* ptr) { |
282 | | if (ptr == nullptr) { |
283 | | ::pagespeed_logging::LogMessage(logging::LOG_FATAL, file, line).stream() |
284 | | << "Check failed: " << expr << " != nullptr"; |
285 | | } |
286 | | return ptr; |
287 | | } |
288 | | |
289 | | #define CHECK_NOTNULL(val) ::CheckNotNull(__FILE__, __LINE__, #val, (val)) |
290 | | |
291 | | // COMPILE_ASSERT - static assertion (use static_assert in C++11+) |
292 | | // Only define if not already defined (basictypes.h may define it first) |
293 | | #ifndef COMPILE_ASSERT |
294 | 0 | #define COMPILE_ASSERT(expr, msg) static_assert(expr, #msg) |
295 | | #endif |
296 | | |
297 | | namespace net_instaweb { |
298 | | |
299 | | // Abstract log sink that can be subclassed by Apache/Envoy/etc. |
300 | | // This provides the same interface as the old glog-based PageSpeedGLogSink |
301 | | class PageSpeedLogSink : public ::pagespeed_logging::LogSink { |
302 | | public: |
303 | | PageSpeedLogSink(); |
304 | | ~PageSpeedLogSink() override; |
305 | | |
306 | | void send(int severity, const char* full_filename, const char* base_filename, |
307 | | int line, const char* message, size_t message_len) override; |
308 | | |
309 | 0 | void setMinLogLevel(int level) { min_log_level_ = level; } |
310 | | |
311 | | protected: |
312 | | int min_log_level_ = logging::LOG_INFO; |
313 | | }; |
314 | | |
315 | | // Alias for backward compatibility |
316 | | using PageSpeedGLogSink = PageSpeedLogSink; |
317 | | |
318 | | } // namespace net_instaweb |