blob: 2ba074ccaeb3f38c7f99748820a2ccf8aa5709eb [file] [log] [blame]
[email protected]34a907732012-01-20 06:33:271// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commitd7cae122008-07-26 21:49:384
[email protected]39be4242008-08-07 18:31:405#ifndef BASE_LOGGING_H_
6#define BASE_LOGGING_H_
initial.commitd7cae122008-07-26 21:49:387
avi9b6f42932015-12-26 22:15:148#include <stddef.h>
9
[email protected]e7972d12011-06-18 11:53:1410#include <cassert>
initial.commitd7cae122008-07-26 21:49:3811#include <cstring>
12#include <sstream>
avi9b6f42932015-12-26 22:15:1413#include <string>
jbroman6bcfec422016-05-26 00:28:4614#include <type_traits>
15#include <utility>
initial.commitd7cae122008-07-26 21:49:3816
[email protected]0bea7252011-08-05 15:34:0017#include "base/base_export.h"
alex-accc1bde62017-04-19 08:33:5518#include "base/callback_forward.h"
danakjcb7c5292016-12-20 19:05:3519#include "base/compiler_specific.h"
[email protected]ddb9b332011-12-02 07:31:0920#include "base/debug/debugger.h"
avi9b6f42932015-12-26 22:15:1421#include "base/macros.h"
alex-accc1bde62017-04-19 08:33:5522#include "base/strings/string_piece_forward.h"
jbroman6bcfec422016-05-26 00:28:4623#include "base/template_util.h"
[email protected]90509cb2011-03-25 18:46:3824#include "build/build_config.h"
initial.commitd7cae122008-07-26 21:49:3825
26//
27// Optional message capabilities
28// -----------------------------
29// Assertion failed messages and fatal errors are displayed in a dialog box
30// before the application exits. However, running this UI creates a message
31// loop, which causes application messages to be processed and potentially
32// dispatched to existing application windows. Since the application is in a
33// bad state when this assertion dialog is displayed, these messages may not
34// get processed and hang the dialog, or the application might go crazy.
35//
36// Therefore, it can be beneficial to display the error dialog in a separate
37// process from the main application. When the logging system needs to display
38// a fatal error dialog box, it will look for a program called
39// "DebugMessage.exe" in the same directory as the application executable. It
40// will run this application with the message as the command line, and will
41// not include the name of the application as is traditional for easier
42// parsing.
43//
44// The code for DebugMessage.exe is only one line. In WinMain, do:
45// MessageBox(NULL, GetCommandLineW(), L"Fatal Error", 0);
46//
47// If DebugMessage.exe is not found, the logging code will use a normal
48// MessageBox, potentially causing the problems discussed above.
49
50
51// Instructions
52// ------------
53//
54// Make a bunch of macros for logging. The way to log things is to stream
55// things to LOG(<a particular severity level>). E.g.,
56//
57// LOG(INFO) << "Found " << num_cookies << " cookies";
58//
59// You can also do conditional logging:
60//
61// LOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
62//
initial.commitd7cae122008-07-26 21:49:3863// The CHECK(condition) macro is active in both debug and release builds and
64// effectively performs a LOG(FATAL) which terminates the process and
65// generates a crashdump unless a debugger is attached.
66//
67// There are also "debug mode" logging macros like the ones above:
68//
69// DLOG(INFO) << "Found cookies";
70//
71// DLOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
72//
73// All "debug mode" logging is compiled away to nothing for non-debug mode
74// compiles. LOG_IF and development flags also work well together
75// because the code can be compiled away sometimes.
76//
77// We also have
78//
79// LOG_ASSERT(assertion);
80// DLOG_ASSERT(assertion);
81//
82// which is syntactic sugar for {,D}LOG_IF(FATAL, assert fails) << assertion;
83//
[email protected]99b7c57f2010-09-29 19:26:3684// There are "verbose level" logging macros. They look like
85//
86// VLOG(1) << "I'm printed when you run the program with --v=1 or more";
87// VLOG(2) << "I'm printed when you run the program with --v=2 or more";
88//
89// These always log at the INFO log level (when they log at all).
90// The verbose logging can also be turned on module-by-module. For instance,
[email protected]b0d38d4c2010-10-29 00:39:4891// --vmodule=profile=2,icon_loader=1,browser_*=3,*/chromeos/*=4 --v=0
[email protected]99b7c57f2010-09-29 19:26:3692// will cause:
93// a. VLOG(2) and lower messages to be printed from profile.{h,cc}
94// b. VLOG(1) and lower messages to be printed from icon_loader.{h,cc}
95// c. VLOG(3) and lower messages to be printed from files prefixed with
96// "browser"
[email protected]e11de722010-11-01 20:50:5597// d. VLOG(4) and lower messages to be printed from files under a
[email protected]b0d38d4c2010-10-29 00:39:4898// "chromeos" directory.
[email protected]e11de722010-11-01 20:50:5599// e. VLOG(0) and lower messages to be printed from elsewhere
[email protected]99b7c57f2010-09-29 19:26:36100//
101// The wildcarding functionality shown by (c) supports both '*' (match
[email protected]b0d38d4c2010-10-29 00:39:48102// 0 or more characters) and '?' (match any single character)
103// wildcards. Any pattern containing a forward or backward slash will
104// be tested against the whole pathname and not just the module.
105// E.g., "*/foo/bar/*=2" would change the logging level for all code
106// in source files under a "foo/bar" directory.
[email protected]99b7c57f2010-09-29 19:26:36107//
108// There's also VLOG_IS_ON(n) "verbose level" condition macro. To be used as
109//
110// if (VLOG_IS_ON(2)) {
111// // do some logging preparation and logging
112// // that can't be accomplished with just VLOG(2) << ...;
113// }
114//
115// There is also a VLOG_IF "verbose level" condition macro for sample
116// cases, when some extra computation and preparation for logs is not
117// needed.
118//
119// VLOG_IF(1, (size > 1024))
120// << "I'm printed when size is more than 1024 and when you run the "
121// "program with --v=1 or more";
122//
initial.commitd7cae122008-07-26 21:49:38123// We also override the standard 'assert' to use 'DLOG_ASSERT'.
124//
[email protected]d8617a62009-10-09 23:52:20125// Lastly, there is:
126//
127// PLOG(ERROR) << "Couldn't do foo";
128// DPLOG(ERROR) << "Couldn't do foo";
129// PLOG_IF(ERROR, cond) << "Couldn't do foo";
130// DPLOG_IF(ERROR, cond) << "Couldn't do foo";
131// PCHECK(condition) << "Couldn't do foo";
132// DPCHECK(condition) << "Couldn't do foo";
133//
134// which append the last system error to the message in string form (taken from
135// GetLastError() on Windows and errno on POSIX).
136//
initial.commitd7cae122008-07-26 21:49:38137// The supported severity levels for macros that allow you to specify one
[email protected]f2c05492014-06-17 12:04:23138// are (in increasing order of severity) INFO, WARNING, ERROR, and FATAL.
initial.commitd7cae122008-07-26 21:49:38139//
140// Very important: logging a message at the FATAL severity level causes
141// the program to terminate (after the message is logged).
[email protected]fb62a532009-02-12 01:19:05142//
[email protected]f2c05492014-06-17 12:04:23143// There is the special severity of DFATAL, which logs FATAL in debug mode,
144// ERROR in normal mode.
initial.commitd7cae122008-07-26 21:49:38145
146namespace logging {
147
[email protected]5e3f7c22013-06-21 21:15:33148// TODO(avi): do we want to do a unification of character types here?
149#if defined(OS_WIN)
150typedef wchar_t PathChar;
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39151#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
[email protected]5e3f7c22013-06-21 21:15:33152typedef char PathChar;
153#endif
154
155// Where to record logging output? A flat file and/or system debug log
156// via OutputDebugString.
157enum LoggingDestination {
158 LOG_NONE = 0,
159 LOG_TO_FILE = 1 << 0,
160 LOG_TO_SYSTEM_DEBUG_LOG = 1 << 1,
161
162 LOG_TO_ALL = LOG_TO_FILE | LOG_TO_SYSTEM_DEBUG_LOG,
163
164 // On Windows, use a file next to the exe; on POSIX platforms, where
165 // it may not even be possible to locate the executable on disk, use
166 // stderr.
167#if defined(OS_WIN)
168 LOG_DEFAULT = LOG_TO_FILE,
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39169#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
[email protected]5e3f7c22013-06-21 21:15:33170 LOG_DEFAULT = LOG_TO_SYSTEM_DEBUG_LOG,
171#endif
172};
initial.commitd7cae122008-07-26 21:49:38173
174// Indicates that the log file should be locked when being written to.
[email protected]5e3f7c22013-06-21 21:15:33175// Unless there is only one single-threaded process that is logging to
176// the log file, the file should be locked during writes to make each
[email protected]3ee50d12014-03-05 01:43:27177// log output atomic. Other writers will block.
initial.commitd7cae122008-07-26 21:49:38178//
179// All processes writing to the log file must have their locking set for it to
[email protected]5e3f7c22013-06-21 21:15:33180// work properly. Defaults to LOCK_LOG_FILE.
initial.commitd7cae122008-07-26 21:49:38181enum LogLockingState { LOCK_LOG_FILE, DONT_LOCK_LOG_FILE };
182
183// On startup, should we delete or append to an existing log file (if any)?
184// Defaults to APPEND_TO_OLD_LOG_FILE.
185enum OldFileDeletionState { DELETE_OLD_LOG_FILE, APPEND_TO_OLD_LOG_FILE };
186
[email protected]5e3f7c22013-06-21 21:15:33187struct BASE_EXPORT LoggingSettings {
188 // The defaults values are:
189 //
190 // logging_dest: LOG_DEFAULT
191 // log_file: NULL
192 // lock_log: LOCK_LOG_FILE
193 // delete_old: APPEND_TO_OLD_LOG_FILE
[email protected]5e3f7c22013-06-21 21:15:33194 LoggingSettings();
195
196 LoggingDestination logging_dest;
197
198 // The three settings below have an effect only when LOG_TO_FILE is
199 // set in |logging_dest|.
200 const PathChar* log_file;
201 LogLockingState lock_log;
202 OldFileDeletionState delete_old;
[email protected]5e3f7c22013-06-21 21:15:33203};
[email protected]ff3d0c32010-08-23 19:57:46204
205// Define different names for the BaseInitLoggingImpl() function depending on
206// whether NDEBUG is defined or not so that we'll fail to link if someone tries
207// to compile logging.cc with NDEBUG but includes logging.h without defining it,
208// or vice versa.
weza245bd072017-06-18 23:26:34209#if defined(NDEBUG)
[email protected]ff3d0c32010-08-23 19:57:46210#define BaseInitLoggingImpl BaseInitLoggingImpl_built_with_NDEBUG
211#else
212#define BaseInitLoggingImpl BaseInitLoggingImpl_built_without_NDEBUG
213#endif
214
215// Implementation of the InitLogging() method declared below. We use a
216// more-specific name so we can #define it above without affecting other code
217// that has named stuff "InitLogging".
[email protected]5e3f7c22013-06-21 21:15:33218BASE_EXPORT bool BaseInitLoggingImpl(const LoggingSettings& settings);
[email protected]ff3d0c32010-08-23 19:57:46219
initial.commitd7cae122008-07-26 21:49:38220// Sets the log file name and other global logging state. Calling this function
221// is recommended, and is normally done at the beginning of application init.
222// If you don't call it, all the flags will be initialized to their default
223// values, and there is a race condition that may leak a critical section
224// object if two threads try to do the first log at the same time.
225// See the definition of the enums above for descriptions and default values.
226//
227// The default log file is initialized to "debug.log" in the application
228// directory. You probably don't want this, especially since the program
229// directory may not be writable on an enduser's system.
[email protected]064aa162011-12-03 00:30:08230//
231// This function may be called a second time to re-direct logging (e.g after
232// loging in to a user partition), however it should never be called more than
233// twice.
[email protected]5e3f7c22013-06-21 21:15:33234inline bool InitLogging(const LoggingSettings& settings) {
235 return BaseInitLoggingImpl(settings);
[email protected]ff3d0c32010-08-23 19:57:46236}
initial.commitd7cae122008-07-26 21:49:38237
238// Sets the log level. Anything at or above this level will be written to the
239// log file/displayed to the user (if applicable). Anything below this level
[email protected]162ac0f2010-11-04 15:50:49240// will be silently ignored. The log level defaults to 0 (everything is logged
241// up to level INFO) if this function is not called.
242// Note that log messages for VLOG(x) are logged at level -x, so setting
243// the min log level to negative values enables verbose logging.
[email protected]0bea7252011-08-05 15:34:00244BASE_EXPORT void SetMinLogLevel(int level);
initial.commitd7cae122008-07-26 21:49:38245
[email protected]8a2986ca2009-04-10 19:13:42246// Gets the current log level.
[email protected]0bea7252011-08-05 15:34:00247BASE_EXPORT int GetMinLogLevel();
initial.commitd7cae122008-07-26 21:49:38248
skobesc78c0ad72015-12-07 20:21:23249// Used by LOG_IS_ON to lazy-evaluate stream arguments.
250BASE_EXPORT bool ShouldCreateLogMessage(int severity);
251
[email protected]162ac0f2010-11-04 15:50:49252// Gets the VLOG default verbosity level.
[email protected]0bea7252011-08-05 15:34:00253BASE_EXPORT int GetVlogVerbosity();
[email protected]162ac0f2010-11-04 15:50:49254
[email protected]2f4e9a62010-09-29 21:25:14255// Note that |N| is the size *with* the null terminator.
[email protected]0bea7252011-08-05 15:34:00256BASE_EXPORT int GetVlogLevelHelper(const char* file_start, size_t N);
[email protected]2f4e9a62010-09-29 21:25:14257
tnagel270da922017-05-24 12:10:44258// Gets the current vlog level for the given file (usually taken from __FILE__).
[email protected]99b7c57f2010-09-29 19:26:36259template <size_t N>
260int GetVlogLevel(const char (&file)[N]) {
261 return GetVlogLevelHelper(file, N);
262}
initial.commitd7cae122008-07-26 21:49:38263
264// Sets the common items you want to be prepended to each log message.
265// process and thread IDs default to off, the timestamp defaults to on.
266// If this function is not called, logging defaults to writing the timestamp
267// only.
[email protected]0bea7252011-08-05 15:34:00268BASE_EXPORT void SetLogItems(bool enable_process_id, bool enable_thread_id,
269 bool enable_timestamp, bool enable_tickcount);
initial.commitd7cae122008-07-26 21:49:38270
James Cooka0536c32018-08-01 20:13:31271// Sets an optional prefix to add to each log message. |prefix| is not copied
272// and should be a raw string constant. |prefix| must only contain ASCII letters
273// to avoid confusion with PIDs and timestamps. Pass null to remove the prefix.
274// Logging defaults to no prefix.
275BASE_EXPORT void SetLogPrefix(const char* prefix);
276
[email protected]81e0a852010-08-17 00:38:12277// Sets whether or not you'd like to see fatal debug messages popped up in
278// a dialog box or not.
279// Dialogs are not shown by default.
[email protected]0bea7252011-08-05 15:34:00280BASE_EXPORT void SetShowErrorDialogs(bool enable_dialogs);
[email protected]81e0a852010-08-17 00:38:12281
initial.commitd7cae122008-07-26 21:49:38282// Sets the Log Assert Handler that will be used to notify of check failures.
alex-accc1bde62017-04-19 08:33:55283// Resets Log Assert Handler on object destruction.
[email protected]fb62a532009-02-12 01:19:05284// The default handler shows a dialog box and then terminate the process,
285// however clients can use this function to override with their own handling
286// (e.g. a silent one for Unit Tests)
alex-accc1bde62017-04-19 08:33:55287using LogAssertHandlerFunction =
288 base::Callback<void(const char* file,
289 int line,
290 const base::StringPiece message,
291 const base::StringPiece stack_trace)>;
292
293class BASE_EXPORT ScopedLogAssertHandler {
294 public:
295 explicit ScopedLogAssertHandler(LogAssertHandlerFunction handler);
296 ~ScopedLogAssertHandler();
297
298 private:
299 DISALLOW_COPY_AND_ASSIGN(ScopedLogAssertHandler);
300};
[email protected]64e5cc02010-11-03 19:20:27301
[email protected]2b07b8412009-11-25 15:26:34302// Sets the Log Message Handler that gets passed every log message before
303// it's sent to other log destinations (if any).
304// Returns true to signal that it handled the message and the message
305// should not be sent to other log destinations.
[email protected]162ac0f2010-11-04 15:50:49306typedef bool (*LogMessageHandlerFunction)(int severity,
307 const char* file, int line, size_t message_start, const std::string& str);
[email protected]0bea7252011-08-05 15:34:00308BASE_EXPORT void SetLogMessageHandler(LogMessageHandlerFunction handler);
309BASE_EXPORT LogMessageHandlerFunction GetLogMessageHandler();
[email protected]2b07b8412009-11-25 15:26:34310
kmarshallfe2f09f82017-04-20 21:05:26311// The ANALYZER_ASSUME_TRUE(bool arg) macro adds compiler-specific hints
312// to Clang which control what code paths are statically analyzed,
313// and is meant to be used in conjunction with assert & assert-like functions.
314// The expression is passed straight through if analysis isn't enabled.
Kevin Marshall7273edd2017-06-20 22:19:36315//
316// ANALYZER_SKIP_THIS_PATH() suppresses static analysis for the current
317// codepath and any other branching codepaths that might follow.
kmarshallfe2f09f82017-04-20 21:05:26318#if defined(__clang_analyzer__)
319
320inline constexpr bool AnalyzerNoReturn() __attribute__((analyzer_noreturn)) {
321 return false;
322}
323
324inline constexpr bool AnalyzerAssumeTrue(bool arg) {
325 // AnalyzerNoReturn() is invoked and analysis is terminated if |arg| is
326 // false.
327 return arg || AnalyzerNoReturn();
328}
329
Kevin Marshall7273edd2017-06-20 22:19:36330#define ANALYZER_ASSUME_TRUE(arg) logging::AnalyzerAssumeTrue(!!(arg))
331#define ANALYZER_SKIP_THIS_PATH() \
332 static_cast<void>(::logging::AnalyzerNoReturn())
Kevin Marshall089565ec2017-07-13 02:57:21333#define ANALYZER_ALLOW_UNUSED(var) static_cast<void>(var);
kmarshallfe2f09f82017-04-20 21:05:26334
335#else // !defined(__clang_analyzer__)
336
337#define ANALYZER_ASSUME_TRUE(arg) (arg)
Kevin Marshall7273edd2017-06-20 22:19:36338#define ANALYZER_SKIP_THIS_PATH()
Kevin Marshall089565ec2017-07-13 02:57:21339#define ANALYZER_ALLOW_UNUSED(var) static_cast<void>(var);
kmarshallfe2f09f82017-04-20 21:05:26340
341#endif // defined(__clang_analyzer__)
342
initial.commitd7cae122008-07-26 21:49:38343typedef int LogSeverity;
[email protected]162ac0f2010-11-04 15:50:49344const LogSeverity LOG_VERBOSE = -1; // This is level 1 verbosity
345// Note: the log severities are used to index into the array of names,
346// see log_severity_names.
initial.commitd7cae122008-07-26 21:49:38347const LogSeverity LOG_INFO = 0;
348const LogSeverity LOG_WARNING = 1;
349const LogSeverity LOG_ERROR = 2;
[email protected]f2c05492014-06-17 12:04:23350const LogSeverity LOG_FATAL = 3;
351const LogSeverity LOG_NUM_SEVERITIES = 4;
initial.commitd7cae122008-07-26 21:49:38352
[email protected]521b0c42010-10-01 23:02:36353// LOG_DFATAL is LOG_FATAL in debug mode, ERROR in normal mode
weza245bd072017-06-18 23:26:34354#if defined(NDEBUG)
[email protected]521b0c42010-10-01 23:02:36355const LogSeverity LOG_DFATAL = LOG_ERROR;
initial.commitd7cae122008-07-26 21:49:38356#else
[email protected]521b0c42010-10-01 23:02:36357const LogSeverity LOG_DFATAL = LOG_FATAL;
initial.commitd7cae122008-07-26 21:49:38358#endif
359
360// A few definitions of macros that don't generate much code. These are used
361// by LOG() and LOG_IF, etc. Since these are used all over our code, it's
362// better to have compact code for these operations.
[email protected]d8617a62009-10-09 23:52:20363#define COMPACT_GOOGLE_LOG_EX_INFO(ClassName, ...) \
tsniatowski612550f2016-07-21 18:26:20364 ::logging::ClassName(__FILE__, __LINE__, ::logging::LOG_INFO, ##__VA_ARGS__)
365#define COMPACT_GOOGLE_LOG_EX_WARNING(ClassName, ...) \
366 ::logging::ClassName(__FILE__, __LINE__, ::logging::LOG_WARNING, \
367 ##__VA_ARGS__)
[email protected]d8617a62009-10-09 23:52:20368#define COMPACT_GOOGLE_LOG_EX_ERROR(ClassName, ...) \
tsniatowski612550f2016-07-21 18:26:20369 ::logging::ClassName(__FILE__, __LINE__, ::logging::LOG_ERROR, ##__VA_ARGS__)
[email protected]d8617a62009-10-09 23:52:20370#define COMPACT_GOOGLE_LOG_EX_FATAL(ClassName, ...) \
tsniatowski612550f2016-07-21 18:26:20371 ::logging::ClassName(__FILE__, __LINE__, ::logging::LOG_FATAL, ##__VA_ARGS__)
[email protected]d8617a62009-10-09 23:52:20372#define COMPACT_GOOGLE_LOG_EX_DFATAL(ClassName, ...) \
tsniatowski612550f2016-07-21 18:26:20373 ::logging::ClassName(__FILE__, __LINE__, ::logging::LOG_DFATAL, ##__VA_ARGS__)
Wez289477f2017-08-24 20:51:30374#define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \
375 ::logging::ClassName(__FILE__, __LINE__, ::logging::LOG_DCHECK, ##__VA_ARGS__)
[email protected]d8617a62009-10-09 23:52:20376
Wez289477f2017-08-24 20:51:30377#define COMPACT_GOOGLE_LOG_INFO COMPACT_GOOGLE_LOG_EX_INFO(LogMessage)
378#define COMPACT_GOOGLE_LOG_WARNING COMPACT_GOOGLE_LOG_EX_WARNING(LogMessage)
379#define COMPACT_GOOGLE_LOG_ERROR COMPACT_GOOGLE_LOG_EX_ERROR(LogMessage)
380#define COMPACT_GOOGLE_LOG_FATAL COMPACT_GOOGLE_LOG_EX_FATAL(LogMessage)
381#define COMPACT_GOOGLE_LOG_DFATAL COMPACT_GOOGLE_LOG_EX_DFATAL(LogMessage)
382#define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_EX_DCHECK(LogMessage)
initial.commitd7cae122008-07-26 21:49:38383
[email protected]8d127302013-01-10 02:41:57384#if defined(OS_WIN)
initial.commitd7cae122008-07-26 21:49:38385// wingdi.h defines ERROR to be 0. When we call LOG(ERROR), it gets
386// substituted with 0, and it expands to COMPACT_GOOGLE_LOG_0. To allow us
387// to keep using this syntax, we define this macro to do the same thing
388// as COMPACT_GOOGLE_LOG_ERROR, and also define ERROR the same way that
389// the Windows SDK does for consistency.
390#define ERROR 0
[email protected]d8617a62009-10-09 23:52:20391#define COMPACT_GOOGLE_LOG_EX_0(ClassName, ...) \
392 COMPACT_GOOGLE_LOG_EX_ERROR(ClassName , ##__VA_ARGS__)
393#define COMPACT_GOOGLE_LOG_0 COMPACT_GOOGLE_LOG_ERROR
[email protected]521b0c42010-10-01 23:02:36394// Needed for LOG_IS_ON(ERROR).
395const LogSeverity LOG_0 = LOG_ERROR;
[email protected]8d127302013-01-10 02:41:57396#endif
[email protected]521b0c42010-10-01 23:02:36397
[email protected]f2c05492014-06-17 12:04:23398// As special cases, we can assume that LOG_IS_ON(FATAL) always holds. Also,
399// LOG_IS_ON(DFATAL) always holds in debug mode. In particular, CHECK()s will
400// always fire if they fail.
[email protected]521b0c42010-10-01 23:02:36401#define LOG_IS_ON(severity) \
skobesc78c0ad72015-12-07 20:21:23402 (::logging::ShouldCreateLogMessage(::logging::LOG_##severity))
[email protected]521b0c42010-10-01 23:02:36403
404// We can't do any caching tricks with VLOG_IS_ON() like the
405// google-glog version since it requires GCC extensions. This means
406// that using the v-logging functions in conjunction with --vmodule
407// may be slow.
408#define VLOG_IS_ON(verboselevel) \
409 ((verboselevel) <= ::logging::GetVlogLevel(__FILE__))
410
411// Helper macro which avoids evaluating the arguments to a stream if
chcunninghamf6a96082015-02-07 01:58:37412// the condition doesn't hold. Condition is evaluated once and only once.
[email protected]521b0c42010-10-01 23:02:36413#define LAZY_STREAM(stream, condition) \
414 !(condition) ? (void) 0 : ::logging::LogMessageVoidify() & (stream)
initial.commitd7cae122008-07-26 21:49:38415
416// We use the preprocessor's merging operator, "##", so that, e.g.,
417// LOG(INFO) becomes the token COMPACT_GOOGLE_LOG_INFO. There's some funny
418// subtle difference between ostream member streaming functions (e.g.,
419// ostream::operator<<(int) and ostream non-member streaming functions
420// (e.g., ::operator<<(ostream&, string&): it turns out that it's
421// impossible to stream something like a string directly to an unnamed
422// ostream. We employ a neat hack by calling the stream() member
423// function of LogMessage which seems to avoid the problem.
[email protected]521b0c42010-10-01 23:02:36424#define LOG_STREAM(severity) COMPACT_GOOGLE_LOG_ ## severity.stream()
initial.commitd7cae122008-07-26 21:49:38425
[email protected]521b0c42010-10-01 23:02:36426#define LOG(severity) LAZY_STREAM(LOG_STREAM(severity), LOG_IS_ON(severity))
427#define LOG_IF(severity, condition) \
428 LAZY_STREAM(LOG_STREAM(severity), LOG_IS_ON(severity) && (condition))
429
[email protected]162ac0f2010-11-04 15:50:49430// The VLOG macros log with negative verbosities.
431#define VLOG_STREAM(verbose_level) \
tsniatowski612550f2016-07-21 18:26:20432 ::logging::LogMessage(__FILE__, __LINE__, -verbose_level).stream()
[email protected]162ac0f2010-11-04 15:50:49433
434#define VLOG(verbose_level) \
435 LAZY_STREAM(VLOG_STREAM(verbose_level), VLOG_IS_ON(verbose_level))
436
437#define VLOG_IF(verbose_level, condition) \
438 LAZY_STREAM(VLOG_STREAM(verbose_level), \
439 VLOG_IS_ON(verbose_level) && (condition))
[email protected]99b7c57f2010-09-29 19:26:36440
[email protected]fb879b1a2011-03-06 18:16:31441#if defined (OS_WIN)
442#define VPLOG_STREAM(verbose_level) \
tsniatowski612550f2016-07-21 18:26:20443 ::logging::Win32ErrorLogMessage(__FILE__, __LINE__, -verbose_level, \
[email protected]fb879b1a2011-03-06 18:16:31444 ::logging::GetLastSystemErrorCode()).stream()
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39445#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
[email protected]fb879b1a2011-03-06 18:16:31446#define VPLOG_STREAM(verbose_level) \
tsniatowski612550f2016-07-21 18:26:20447 ::logging::ErrnoLogMessage(__FILE__, __LINE__, -verbose_level, \
[email protected]fb879b1a2011-03-06 18:16:31448 ::logging::GetLastSystemErrorCode()).stream()
449#endif
450
451#define VPLOG(verbose_level) \
452 LAZY_STREAM(VPLOG_STREAM(verbose_level), VLOG_IS_ON(verbose_level))
453
454#define VPLOG_IF(verbose_level, condition) \
455 LAZY_STREAM(VPLOG_STREAM(verbose_level), \
456 VLOG_IS_ON(verbose_level) && (condition))
457
[email protected]99b7c57f2010-09-29 19:26:36458// TODO(akalin): Add more VLOG variants, e.g. VPLOG.
initial.commitd7cae122008-07-26 21:49:38459
kmarshallfe2f09f82017-04-20 21:05:26460#define LOG_ASSERT(condition) \
461 LOG_IF(FATAL, !(ANALYZER_ASSUME_TRUE(condition))) \
462 << "Assert failed: " #condition ". "
initial.commitd7cae122008-07-26 21:49:38463
[email protected]d8617a62009-10-09 23:52:20464#if defined(OS_WIN)
[email protected]c914d8a2014-04-23 01:11:01465#define PLOG_STREAM(severity) \
[email protected]d8617a62009-10-09 23:52:20466 COMPACT_GOOGLE_LOG_EX_ ## severity(Win32ErrorLogMessage, \
467 ::logging::GetLastSystemErrorCode()).stream()
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39468#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
[email protected]c914d8a2014-04-23 01:11:01469#define PLOG_STREAM(severity) \
[email protected]d8617a62009-10-09 23:52:20470 COMPACT_GOOGLE_LOG_EX_ ## severity(ErrnoLogMessage, \
471 ::logging::GetLastSystemErrorCode()).stream()
[email protected]d8617a62009-10-09 23:52:20472#endif
473
[email protected]521b0c42010-10-01 23:02:36474#define PLOG(severity) \
475 LAZY_STREAM(PLOG_STREAM(severity), LOG_IS_ON(severity))
476
[email protected]d8617a62009-10-09 23:52:20477#define PLOG_IF(severity, condition) \
[email protected]521b0c42010-10-01 23:02:36478 LAZY_STREAM(PLOG_STREAM(severity), LOG_IS_ON(severity) && (condition))
[email protected]d8617a62009-10-09 23:52:20479
scottmg3c957a52016-12-10 20:57:59480BASE_EXPORT extern std::ostream* g_swallow_stream;
481
482// Note that g_swallow_stream is used instead of an arbitrary LOG() stream to
483// avoid the creation of an object with a non-trivial destructor (LogMessage).
484// On MSVC x86 (checked on 2015 Update 3), this causes a few additional
485// pointless instructions to be emitted even at full optimization level, even
486// though the : arm of the ternary operator is clearly never executed. Using a
487// simpler object to be &'d with Voidify() avoids these extra instructions.
488// Using a simpler POD object with a templated operator<< also works to avoid
489// these instructions. However, this causes warnings on statically defined
490// implementations of operator<<(std::ostream, ...) in some .cc files, because
491// they become defined-but-unreferenced functions. A reinterpret_cast of 0 to an
492// ostream* also is not suitable, because some compilers warn of undefined
493// behavior.
494#define EAT_STREAM_PARAMETERS \
495 true ? (void)0 \
496 : ::logging::LogMessageVoidify() & (*::logging::g_swallow_stream)
[email protected]ddb9b332011-12-02 07:31:09497
erikwright6ad937b2015-07-22 20:05:52498// Captures the result of a CHECK_EQ (for example) and facilitates testing as a
499// boolean.
500class CheckOpResult {
501 public:
wezf01a9b72016-03-19 01:18:07502 // |message| must be non-null if and only if the check failed.
erikwright6ad937b2015-07-22 20:05:52503 CheckOpResult(std::string* message) : message_(message) {}
504 // Returns true if the check succeeded.
505 operator bool() const { return !message_; }
506 // Returns the message.
507 std::string* message() { return message_; }
508
509 private:
510 std::string* message_;
511};
512
primianof5316722017-02-21 13:09:26513// Crashes in the fastest possible way with no attempt at logging.
514// There are different constraints to satisfy here, see http://crbug.com/664209
515// for more context:
516// - The trap instructions, and hence the PC value at crash time, have to be
517// distinct and not get folded into the same opcode by the compiler.
518// On Linux/Android this is tricky because GCC still folds identical
519// asm volatile blocks. The workaround is generating distinct opcodes for
520// each CHECK using the __COUNTER__ macro.
521// - The debug info for the trap instruction has to be attributed to the source
522// line that has the CHECK(), to make crash reports actionable. This rules
523// out the ability of using a inline function, at least as long as clang
524// doesn't support attribute(artificial).
525// - Failed CHECKs should produce a signal that is distinguishable from an
526// invalid memory access, to improve the actionability of crash reports.
527// - The compiler should treat the CHECK as no-return instructions, so that the
528// trap code can be efficiently packed in the prologue of the function and
529// doesn't interfere with the main execution flow.
530// - When debugging, developers shouldn't be able to accidentally step over a
531// CHECK. This is achieved by putting opcodes that will cause a non
532// continuable exception after the actual trap instruction.
533// - Don't cause too much binary bloat.
scottmga17c8db2017-02-15 21:35:49534#if defined(COMPILER_GCC)
primianof5316722017-02-21 13:09:26535
536#if defined(ARCH_CPU_X86_FAMILY) && !defined(OS_NACL)
537// int 3 will generate a SIGTRAP.
538#define TRAP_SEQUENCE() \
539 asm volatile( \
540 "int3; ud2; push %0;" ::"i"(static_cast<unsigned char>(__COUNTER__)))
541
542#elif defined(ARCH_CPU_ARMEL) && !defined(OS_NACL)
543// bkpt will generate a SIGBUS when running on armv7 and a SIGTRAP when running
544// as a 32 bit userspace app on arm64. There doesn't seem to be any way to
545// cause a SIGTRAP from userspace without using a syscall (which would be a
546// problem for sandboxing).
547#define TRAP_SEQUENCE() \
548 asm volatile("bkpt #0; udf %0;" ::"i"(__COUNTER__ % 256))
549
550#elif defined(ARCH_CPU_ARM64) && !defined(OS_NACL)
551// This will always generate a SIGTRAP on arm64.
552#define TRAP_SEQUENCE() \
553 asm volatile("brk #0; hlt %0;" ::"i"(__COUNTER__ % 65536))
554
555#else
556// Crash report accuracy will not be guaranteed on other architectures, but at
557// least this will crash as expected.
558#define TRAP_SEQUENCE() __builtin_trap()
559#endif // ARCH_CPU_*
560
Jose Dapena Paz9679430d2018-03-17 00:41:20561// CHECK() and the trap sequence can be invoked from a constexpr function.
562// This could make compilation fail on GCC, as it forbids directly using inline
563// asm inside a constexpr function. However, it allows calling a lambda
564// expression including the same asm.
565// The side effect is that the top of the stacktrace will not point to the
566// calling function, but to this anonymous lambda. This is still useful as the
567// full name of the lambda will typically include the name of the function that
568// calls CHECK() and the debugger will still break at the right line of code.
569#if !defined(__clang__)
570#define WRAPPED_TRAP_SEQUENCE() \
571 do { \
572 [] { TRAP_SEQUENCE(); }(); \
573 } while (false)
574#else
575#define WRAPPED_TRAP_SEQUENCE() TRAP_SEQUENCE()
576#endif
577
primianof5316722017-02-21 13:09:26578#define IMMEDIATE_CRASH() \
579 ({ \
Jose Dapena Paz9679430d2018-03-17 00:41:20580 WRAPPED_TRAP_SEQUENCE(); \
primianof5316722017-02-21 13:09:26581 __builtin_unreachable(); \
582 })
583
scottmga17c8db2017-02-15 21:35:49584#elif defined(COMPILER_MSVC)
scottmg92bbdc392017-02-20 21:06:25585
586// Clang is cleverer about coalescing int3s, so we need to add a unique-ish
587// instruction following the __debugbreak() to have it emit distinct locations
588// for CHECKs rather than collapsing them all together. It would be nice to use
589// a short intrinsic to do this (and perhaps have only one implementation for
scottmg6a233062017-02-21 23:52:14590// both clang and MSVC), however clang-cl currently does not support intrinsics.
591// On the flip side, MSVC x64 doesn't support inline asm. So, we have to have
592// two implementations. Normally clang-cl's version will be 5 bytes (1 for
593// `int3`, 2 for `ud2`, 2 for `push byte imm`, however, TODO(scottmg):
594// https://crbug.com/694670 clang-cl doesn't currently support %'ing
595// __COUNTER__, so eventually it will emit the dword form of push.
scottmg92bbdc392017-02-20 21:06:25596// TODO(scottmg): Reinvestigate a short sequence that will work on both
597// compilers once clang supports more intrinsics. See https://crbug.com/693713.
598#if defined(__clang__)
Wez5f117412018-02-07 04:17:47599#define IMMEDIATE_CRASH() \
600 ({ \
601 {__asm int 3 __asm ud2 __asm push __COUNTER__}; \
602 __builtin_unreachable(); \
603 })
scottmg92bbdc392017-02-20 21:06:25604#else
scottmga17c8db2017-02-15 21:35:49605#define IMMEDIATE_CRASH() __debugbreak()
scottmg92bbdc392017-02-20 21:06:25606#endif // __clang__
607
Chris Palmer61343b02016-11-29 20:44:10608#else
scottmga17c8db2017-02-15 21:35:49609#error Port
Chris Palmer61343b02016-11-29 20:44:10610#endif
611
initial.commitd7cae122008-07-26 21:49:38612// CHECK dies with a fatal error if condition is not true. It is *not*
613// controlled by NDEBUG, so the check will be executed regardless of
614// compilation mode.
[email protected]521b0c42010-10-01 23:02:36615//
616// We make sure CHECK et al. always evaluates their arguments, as
617// doing CHECK(FunctionWithSideEffect()) is a common idiom.
[email protected]ddb9b332011-12-02 07:31:09618
danakjb9d59312016-05-04 20:06:31619#if defined(OFFICIAL_BUILD) && defined(NDEBUG)
[email protected]ddb9b332011-12-02 07:31:09620
Chris Palmer61343b02016-11-29 20:44:10621// Make all CHECK functions discard their log strings to reduce code bloat, and
622// improve performance, for official release builds.
623//
primianoba910a62016-07-07 22:14:48624// This is not calling BreakDebugger since this is called frequently, and
625// calling an out-of-line function instead of a noreturn inline macro prevents
626// compiler optimizations.
Chris Palmer61343b02016-11-29 20:44:10627#define CHECK(condition) \
danakjcb7c5292016-12-20 19:05:35628 UNLIKELY(!(condition)) ? IMMEDIATE_CRASH() : EAT_STREAM_PARAMETERS
[email protected]ddb9b332011-12-02 07:31:09629
Robert Sesekd2f495f2017-07-25 22:03:14630// PCHECK includes the system error code, which is useful for determining
631// why the condition failed. In official builds, preserve only the error code
632// message so that it is available in crash reports. The stringified
633// condition and any additional stream parameters are dropped.
634#define PCHECK(condition) \
635 LAZY_STREAM(PLOG_STREAM(FATAL), UNLIKELY(!(condition))); \
636 EAT_STREAM_PARAMETERS
[email protected]ddb9b332011-12-02 07:31:09637
638#define CHECK_OP(name, op, val1, val2) CHECK((val1) op (val2))
639
danakjb9d59312016-05-04 20:06:31640#else // !(OFFICIAL_BUILD && NDEBUG)
[email protected]ddb9b332011-12-02 07:31:09641
kmarshall08c892f72017-02-28 03:46:18642#if defined(_PREFAST_) && defined(OS_WIN)
643// Use __analysis_assume to tell the VC++ static analysis engine that
644// assert conditions are true, to suppress warnings. The LAZY_STREAM
645// parameter doesn't reference 'condition' in /analyze builds because
646// this evaluation confuses /analyze. The !! before condition is because
647// __analysis_assume gets confused on some conditions:
648// http://randomascii.wordpress.com/2011/09/13/analyze-for-visual-studio-the-ugly-part-5/
649
650#define CHECK(condition) \
651 __analysis_assume(!!(condition)), \
652 LAZY_STREAM(LOG_STREAM(FATAL), false) \
653 << "Check failed: " #condition ". "
654
655#define PCHECK(condition) \
656 __analysis_assume(!!(condition)), \
657 LAZY_STREAM(PLOG_STREAM(FATAL), false) \
658 << "Check failed: " #condition ". "
659
660#else // _PREFAST_
661
tnagel4a045d3f2015-07-12 14:19:28662// Do as much work as possible out of line to reduce inline code size.
tsniatowski612550f2016-07-21 18:26:20663#define CHECK(condition) \
664 LAZY_STREAM(::logging::LogMessage(__FILE__, __LINE__, #condition).stream(), \
kmarshallfe2f09f82017-04-20 21:05:26665 !ANALYZER_ASSUME_TRUE(condition))
initial.commitd7cae122008-07-26 21:49:38666
kmarshallfe2f09f82017-04-20 21:05:26667#define PCHECK(condition) \
668 LAZY_STREAM(PLOG_STREAM(FATAL), !ANALYZER_ASSUME_TRUE(condition)) \
kmarshalle23eed02017-02-11 02:13:23669 << "Check failed: " #condition ". "
brucedawson9d160252014-10-23 20:14:14670
kmarshall08c892f72017-02-28 03:46:18671#endif // _PREFAST_
672
[email protected]ddb9b332011-12-02 07:31:09673// Helper macro for binary operators.
674// Don't use this macro directly in your code, use CHECK_EQ et al below.
erikwright6ad937b2015-07-22 20:05:52675// The 'switch' is used to prevent the 'else' from being ambiguous when the
676// macro is used in an 'if' clause such as:
677// if (a == 1)
678// CHECK_EQ(2, a);
679#define CHECK_OP(name, op, val1, val2) \
680 switch (0) case 0: default: \
tsniatowski612550f2016-07-21 18:26:20681 if (::logging::CheckOpResult true_if_passed = \
682 ::logging::Check##name##Impl((val1), (val2), \
683 #val1 " " #op " " #val2)) \
erikwright6ad937b2015-07-22 20:05:52684 ; \
685 else \
tsniatowski612550f2016-07-21 18:26:20686 ::logging::LogMessage(__FILE__, __LINE__, true_if_passed.message()).stream()
[email protected]ddb9b332011-12-02 07:31:09687
danakjb9d59312016-05-04 20:06:31688#endif // !(OFFICIAL_BUILD && NDEBUG)
[email protected]ddb9b332011-12-02 07:31:09689
brucedawson93a60b8c2016-04-28 20:46:16690// This formats a value for a failing CHECK_XX statement. Ordinarily,
691// it uses the definition for operator<<, with a few special cases below.
692template <typename T>
jbroman6bcfec422016-05-26 00:28:46693inline typename std::enable_if<
raphael.kubo.da.costa81f21202016-11-28 18:36:36694 base::internal::SupportsOstreamOperator<const T&>::value &&
695 !std::is_function<typename std::remove_pointer<T>::type>::value,
jbroman6bcfec422016-05-26 00:28:46696 void>::type
697MakeCheckOpValueString(std::ostream* os, const T& v) {
brucedawson93a60b8c2016-04-28 20:46:16698 (*os) << v;
699}
700
raphael.kubo.da.costa81f21202016-11-28 18:36:36701// Provide an overload for functions and function pointers. Function pointers
702// don't implicitly convert to void* but do implicitly convert to bool, so
703// without this function pointers are always printed as 1 or 0. (MSVC isn't
704// standards-conforming here and converts function pointers to regular
705// pointers, so this is a no-op for MSVC.)
706template <typename T>
707inline typename std::enable_if<
708 std::is_function<typename std::remove_pointer<T>::type>::value,
709 void>::type
710MakeCheckOpValueString(std::ostream* os, const T& v) {
711 (*os) << reinterpret_cast<const void*>(v);
712}
713
jbroman6bcfec422016-05-26 00:28:46714// We need overloads for enums that don't support operator<<.
715// (i.e. scoped enums where no operator<< overload was declared).
716template <typename T>
717inline typename std::enable_if<
718 !base::internal::SupportsOstreamOperator<const T&>::value &&
719 std::is_enum<T>::value,
720 void>::type
721MakeCheckOpValueString(std::ostream* os, const T& v) {
danakj6d0446e52017-04-05 16:22:29722 (*os) << static_cast<typename std::underlying_type<T>::type>(v);
jbroman6bcfec422016-05-26 00:28:46723}
724
725// We need an explicit overload for std::nullptr_t.
726BASE_EXPORT void MakeCheckOpValueString(std::ostream* os, std::nullptr_t p);
brucedawson93a60b8c2016-04-28 20:46:16727
initial.commitd7cae122008-07-26 21:49:38728// Build the error message string. This is separate from the "Impl"
729// function template because it is not performance critical and so can
[email protected]9c7132e2011-02-08 07:39:08730// be out of line, while the "Impl" code should be inline. Caller
731// takes ownership of the returned string.
initial.commitd7cae122008-07-26 21:49:38732template<class t1, class t2>
733std::string* MakeCheckOpString(const t1& v1, const t2& v2, const char* names) {
734 std::ostringstream ss;
brucedawson93a60b8c2016-04-28 20:46:16735 ss << names << " (";
736 MakeCheckOpValueString(&ss, v1);
737 ss << " vs. ";
738 MakeCheckOpValueString(&ss, v2);
739 ss << ")";
initial.commitd7cae122008-07-26 21:49:38740 std::string* msg = new std::string(ss.str());
741 return msg;
742}
743
[email protected]6d445d32010-09-30 19:10:03744// Commonly used instantiations of MakeCheckOpString<>. Explicitly instantiated
745// in logging.cc.
[email protected]dc72da32011-10-24 20:20:30746extern template BASE_EXPORT std::string* MakeCheckOpString<int, int>(
[email protected]6d445d32010-09-30 19:10:03747 const int&, const int&, const char* names);
[email protected]dc72da32011-10-24 20:20:30748extern template BASE_EXPORT
749std::string* MakeCheckOpString<unsigned long, unsigned long>(
[email protected]6d445d32010-09-30 19:10:03750 const unsigned long&, const unsigned long&, const char* names);
[email protected]dc72da32011-10-24 20:20:30751extern template BASE_EXPORT
752std::string* MakeCheckOpString<unsigned long, unsigned int>(
[email protected]6d445d32010-09-30 19:10:03753 const unsigned long&, const unsigned int&, const char* names);
[email protected]dc72da32011-10-24 20:20:30754extern template BASE_EXPORT
755std::string* MakeCheckOpString<unsigned int, unsigned long>(
[email protected]6d445d32010-09-30 19:10:03756 const unsigned int&, const unsigned long&, const char* names);
[email protected]dc72da32011-10-24 20:20:30757extern template BASE_EXPORT
758std::string* MakeCheckOpString<std::string, std::string>(
[email protected]6d445d32010-09-30 19:10:03759 const std::string&, const std::string&, const char* name);
initial.commitd7cae122008-07-26 21:49:38760
[email protected]71512602010-11-01 22:19:56761// Helper functions for CHECK_OP macro.
762// The (int, int) specialization works around the issue that the compiler
763// will not instantiate the template version of the function on values of
764// unnamed enum type - see comment below.
kmarshallfe2f09f82017-04-20 21:05:26765//
766// The checked condition is wrapped with ANALYZER_ASSUME_TRUE, which under
767// static analysis builds, blocks analysis of the current path if the
768// condition is false.
kmarshall9db26fb2017-02-15 01:05:33769#define DEFINE_CHECK_OP_IMPL(name, op) \
770 template <class t1, class t2> \
771 inline std::string* Check##name##Impl(const t1& v1, const t2& v2, \
772 const char* names) { \
kmarshallfe2f09f82017-04-20 21:05:26773 if (ANALYZER_ASSUME_TRUE(v1 op v2)) \
kmarshall9db26fb2017-02-15 01:05:33774 return NULL; \
775 else \
776 return ::logging::MakeCheckOpString(v1, v2, names); \
777 } \
[email protected]71512602010-11-01 22:19:56778 inline std::string* Check##name##Impl(int v1, int v2, const char* names) { \
kmarshallfe2f09f82017-04-20 21:05:26779 if (ANALYZER_ASSUME_TRUE(v1 op v2)) \
kmarshall9db26fb2017-02-15 01:05:33780 return NULL; \
781 else \
782 return ::logging::MakeCheckOpString(v1, v2, names); \
[email protected]71512602010-11-01 22:19:56783 }
784DEFINE_CHECK_OP_IMPL(EQ, ==)
785DEFINE_CHECK_OP_IMPL(NE, !=)
786DEFINE_CHECK_OP_IMPL(LE, <=)
787DEFINE_CHECK_OP_IMPL(LT, < )
788DEFINE_CHECK_OP_IMPL(GE, >=)
789DEFINE_CHECK_OP_IMPL(GT, > )
790#undef DEFINE_CHECK_OP_IMPL
[email protected]e150c0382010-03-02 00:41:12791
792#define CHECK_EQ(val1, val2) CHECK_OP(EQ, ==, val1, val2)
793#define CHECK_NE(val1, val2) CHECK_OP(NE, !=, val1, val2)
794#define CHECK_LE(val1, val2) CHECK_OP(LE, <=, val1, val2)
795#define CHECK_LT(val1, val2) CHECK_OP(LT, < , val1, val2)
796#define CHECK_GE(val1, val2) CHECK_OP(GE, >=, val1, val2)
797#define CHECK_GT(val1, val2) CHECK_OP(GT, > , val1, val2)
798
jam121900aa2016-04-19 00:07:34799#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
danakje649f572015-01-08 23:35:58800#define DCHECK_IS_ON() 0
[email protected]1a1505512014-03-10 18:23:38801#else
danakje649f572015-01-08 23:35:58802#define DCHECK_IS_ON() 1
[email protected]e3cca332009-08-20 01:20:29803#endif
804
[email protected]d15e56c2010-09-30 21:12:33805// Definitions for DLOG et al.
806
gab190f7542016-08-01 20:03:41807#if DCHECK_IS_ON()
[email protected]d926c202010-10-01 02:58:24808
[email protected]5e987802010-11-01 19:49:22809#define DLOG_IS_ON(severity) LOG_IS_ON(severity)
[email protected]d926c202010-10-01 02:58:24810#define DLOG_IF(severity, condition) LOG_IF(severity, condition)
811#define DLOG_ASSERT(condition) LOG_ASSERT(condition)
[email protected]d926c202010-10-01 02:58:24812#define DPLOG_IF(severity, condition) PLOG_IF(severity, condition)
[email protected]521b0c42010-10-01 23:02:36813#define DVLOG_IF(verboselevel, condition) VLOG_IF(verboselevel, condition)
[email protected]fb879b1a2011-03-06 18:16:31814#define DVPLOG_IF(verboselevel, condition) VPLOG_IF(verboselevel, condition)
[email protected]d926c202010-10-01 02:58:24815
gab190f7542016-08-01 20:03:41816#else // DCHECK_IS_ON()
[email protected]d926c202010-10-01 02:58:24817
gab190f7542016-08-01 20:03:41818// If !DCHECK_IS_ON(), we want to avoid emitting any references to |condition|
819// (which may reference a variable defined only if DCHECK_IS_ON()).
820// Contrast this with DCHECK et al., which has different behavior.
[email protected]d926c202010-10-01 02:58:24821
[email protected]5e987802010-11-01 19:49:22822#define DLOG_IS_ON(severity) false
[email protected]ddb9b332011-12-02 07:31:09823#define DLOG_IF(severity, condition) EAT_STREAM_PARAMETERS
824#define DLOG_ASSERT(condition) EAT_STREAM_PARAMETERS
825#define DPLOG_IF(severity, condition) EAT_STREAM_PARAMETERS
826#define DVLOG_IF(verboselevel, condition) EAT_STREAM_PARAMETERS
827#define DVPLOG_IF(verboselevel, condition) EAT_STREAM_PARAMETERS
[email protected]d926c202010-10-01 02:58:24828
gab190f7542016-08-01 20:03:41829#endif // DCHECK_IS_ON()
[email protected]d926c202010-10-01 02:58:24830
[email protected]521b0c42010-10-01 23:02:36831#define DLOG(severity) \
832 LAZY_STREAM(LOG_STREAM(severity), DLOG_IS_ON(severity))
833
[email protected]521b0c42010-10-01 23:02:36834#define DPLOG(severity) \
835 LAZY_STREAM(PLOG_STREAM(severity), DLOG_IS_ON(severity))
836
[email protected]c3ab11c2011-10-25 06:28:45837#define DVLOG(verboselevel) DVLOG_IF(verboselevel, VLOG_IS_ON(verboselevel))
[email protected]521b0c42010-10-01 23:02:36838
[email protected]fb879b1a2011-03-06 18:16:31839#define DVPLOG(verboselevel) DVPLOG_IF(verboselevel, VLOG_IS_ON(verboselevel))
840
[email protected]521b0c42010-10-01 23:02:36841// Definitions for DCHECK et al.
[email protected]d926c202010-10-01 02:58:24842
danakje649f572015-01-08 23:35:58843#if DCHECK_IS_ON()
[email protected]e3cca332009-08-20 01:20:29844
Weza6ca5b92018-03-23 19:03:07845#if DCHECK_IS_CONFIGURABLE
Wez289477f2017-08-24 20:51:30846BASE_EXPORT extern LogSeverity LOG_DCHECK;
847#else
[email protected]521b0c42010-10-01 23:02:36848const LogSeverity LOG_DCHECK = LOG_FATAL;
Wez289477f2017-08-24 20:51:30849#endif
[email protected]521b0c42010-10-01 23:02:36850
danakje649f572015-01-08 23:35:58851#else // DCHECK_IS_ON()
[email protected]521b0c42010-10-01 23:02:36852
Sigurdur Asgeirsson7013e5f2017-09-29 17:42:58853// There may be users of LOG_DCHECK that are enabled independently
854// of DCHECK_IS_ON(), so default to FATAL logging for those.
855const LogSeverity LOG_DCHECK = LOG_FATAL;
[email protected]521b0c42010-10-01 23:02:36856
danakje649f572015-01-08 23:35:58857#endif // DCHECK_IS_ON()
[email protected]521b0c42010-10-01 23:02:36858
[email protected]deba0ff2010-11-03 05:30:14859// DCHECK et al. make sure to reference |condition| regardless of
[email protected]521b0c42010-10-01 23:02:36860// whether DCHECKs are enabled; this is so that we don't get unused
861// variable warnings if the only use of a variable is in a DCHECK.
862// This behavior is different from DLOG_IF et al.
dchengfc670f472017-01-25 17:48:43863//
864// Note that the definition of the DCHECK macros depends on whether or not
865// DCHECK_IS_ON() is true. When DCHECK_IS_ON() is false, the macros use
866// EAT_STREAM_PARAMETERS to avoid expressions that would create temporaries.
[email protected]521b0c42010-10-01 23:02:36867
kmarshall08c892f72017-02-28 03:46:18868#if defined(_PREFAST_) && defined(OS_WIN)
869// See comments on the previous use of __analysis_assume.
870
871#define DCHECK(condition) \
872 __analysis_assume(!!(condition)), \
873 LAZY_STREAM(LOG_STREAM(DCHECK), false) \
874 << "Check failed: " #condition ". "
875
876#define DPCHECK(condition) \
877 __analysis_assume(!!(condition)), \
878 LAZY_STREAM(PLOG_STREAM(DCHECK), false) \
879 << "Check failed: " #condition ". "
880
kmarshallfe2f09f82017-04-20 21:05:26881#else // !(defined(_PREFAST_) && defined(OS_WIN))
kmarshall08c892f72017-02-28 03:46:18882
dchengfc670f472017-01-25 17:48:43883#if DCHECK_IS_ON()
884
kmarshallfe2f09f82017-04-20 21:05:26885#define DCHECK(condition) \
886 LAZY_STREAM(LOG_STREAM(DCHECK), !ANALYZER_ASSUME_TRUE(condition)) \
dchengfc670f472017-01-25 17:48:43887 << "Check failed: " #condition ". "
kmarshallfe2f09f82017-04-20 21:05:26888#define DPCHECK(condition) \
889 LAZY_STREAM(PLOG_STREAM(DCHECK), !ANALYZER_ASSUME_TRUE(condition)) \
danakje649f572015-01-08 23:35:58890 << "Check failed: " #condition ". "
[email protected]521b0c42010-10-01 23:02:36891
dchengfc670f472017-01-25 17:48:43892#else // DCHECK_IS_ON()
893
kmarshall08c892f72017-02-28 03:46:18894#define DCHECK(condition) EAT_STREAM_PARAMETERS << !(condition)
895#define DPCHECK(condition) EAT_STREAM_PARAMETERS << !(condition)
dchengfc670f472017-01-25 17:48:43896
897#endif // DCHECK_IS_ON()
[email protected]d926c202010-10-01 02:58:24898
kmarshallfe2f09f82017-04-20 21:05:26899#endif // defined(_PREFAST_) && defined(OS_WIN)
brucedawson9d160252014-10-23 20:14:14900
[email protected]d926c202010-10-01 02:58:24901// Helper macro for binary operators.
902// Don't use this macro directly in your code, use DCHECK_EQ et al below.
erikwright6ad937b2015-07-22 20:05:52903// The 'switch' is used to prevent the 'else' from being ambiguous when the
904// macro is used in an 'if' clause such as:
905// if (a == 1)
906// DCHECK_EQ(2, a);
dchengfc670f472017-01-25 17:48:43907#if DCHECK_IS_ON()
908
tsniatowski612550f2016-07-21 18:26:20909#define DCHECK_OP(name, op, val1, val2) \
910 switch (0) case 0: default: \
911 if (::logging::CheckOpResult true_if_passed = \
tsniatowski612550f2016-07-21 18:26:20912 ::logging::Check##name##Impl((val1), (val2), \
Wez6a592ee2018-05-25 20:29:07913 #val1 " " #op " " #val2)) \
tsniatowski612550f2016-07-21 18:26:20914 ; \
915 else \
916 ::logging::LogMessage(__FILE__, __LINE__, ::logging::LOG_DCHECK, \
917 true_if_passed.message()).stream()
initial.commitd7cae122008-07-26 21:49:38918
dchengfc670f472017-01-25 17:48:43919#else // DCHECK_IS_ON()
920
921// When DCHECKs aren't enabled, DCHECK_OP still needs to reference operator<<
922// overloads for |val1| and |val2| to avoid potential compiler warnings about
923// unused functions. For the same reason, it also compares |val1| and |val2|
924// using |op|.
925//
926// Note that the contract of DCHECK_EQ, etc is that arguments are only evaluated
927// once. Even though |val1| and |val2| appear twice in this version of the macro
928// expansion, this is OK, since the expression is never actually evaluated.
929#define DCHECK_OP(name, op, val1, val2) \
930 EAT_STREAM_PARAMETERS << (::logging::MakeCheckOpValueString( \
931 ::logging::g_swallow_stream, val1), \
932 ::logging::MakeCheckOpValueString( \
933 ::logging::g_swallow_stream, val2), \
kmarshall08c892f72017-02-28 03:46:18934 (val1)op(val2))
dchengfc670f472017-01-25 17:48:43935
936#endif // DCHECK_IS_ON()
937
[email protected]deba0ff2010-11-03 05:30:14938// Equality/Inequality checks - compare two values, and log a
939// LOG_DCHECK message including the two values when the result is not
940// as expected. The values must have operator<<(ostream, ...)
941// defined.
initial.commitd7cae122008-07-26 21:49:38942//
943// You may append to the error message like so:
pwnall7ae42b462016-09-22 02:26:12944// DCHECK_NE(1, 2) << "The world must be ending!";
initial.commitd7cae122008-07-26 21:49:38945//
946// We are very careful to ensure that each argument is evaluated exactly
947// once, and that anything which is legal to pass as a function argument is
948// legal here. In particular, the arguments may be temporary expressions
949// which will end up being destroyed at the end of the apparent statement,
950// for example:
951// DCHECK_EQ(string("abc")[1], 'b');
952//
brucedawson93a60b8c2016-04-28 20:46:16953// WARNING: These don't compile correctly if one of the arguments is a pointer
954// and the other is NULL. In new code, prefer nullptr instead. To
955// work around this for C++98, simply static_cast NULL to the type of the
956// desired pointer.
initial.commitd7cae122008-07-26 21:49:38957
958#define DCHECK_EQ(val1, val2) DCHECK_OP(EQ, ==, val1, val2)
959#define DCHECK_NE(val1, val2) DCHECK_OP(NE, !=, val1, val2)
960#define DCHECK_LE(val1, val2) DCHECK_OP(LE, <=, val1, val2)
961#define DCHECK_LT(val1, val2) DCHECK_OP(LT, < , val1, val2)
962#define DCHECK_GE(val1, val2) DCHECK_OP(GE, >=, val1, val2)
963#define DCHECK_GT(val1, val2) DCHECK_OP(GT, > , val1, val2)
964
danakje649f572015-01-08 23:35:58965#if !DCHECK_IS_ON() && defined(OS_CHROMEOS)
tnagelff3f34a2015-05-24 12:59:14966// Implement logging of NOTREACHED() as a dedicated function to get function
967// call overhead down to a minimum.
968void LogErrorNotReached(const char* file, int line);
969#define NOTREACHED() \
970 true ? ::logging::LogErrorNotReached(__FILE__, __LINE__) \
971 : EAT_STREAM_PARAMETERS
[email protected]7c67fbe2013-09-26 07:55:21972#else
initial.commitd7cae122008-07-26 21:49:38973#define NOTREACHED() DCHECK(false)
[email protected]7c67fbe2013-09-26 07:55:21974#endif
initial.commitd7cae122008-07-26 21:49:38975
976// Redefine the standard assert to use our nice log files
977#undef assert
978#define assert(x) DLOG_ASSERT(x)
979
980// This class more or less represents a particular log message. You
981// create an instance of LogMessage and then stream stuff to it.
982// When you finish streaming to it, ~LogMessage is called and the
983// full message gets streamed to the appropriate destination.
984//
985// You shouldn't actually use LogMessage's constructor to log things,
986// though. You should use the LOG() macro (and variants thereof)
987// above.
[email protected]0bea7252011-08-05 15:34:00988class BASE_EXPORT LogMessage {
initial.commitd7cae122008-07-26 21:49:38989 public:
[email protected]bf8ddf13a2014-06-18 15:02:22990 // Used for LOG(severity).
initial.commitd7cae122008-07-26 21:49:38991 LogMessage(const char* file, int line, LogSeverity severity);
992
tnagel4a045d3f2015-07-12 14:19:28993 // Used for CHECK(). Implied severity = LOG_FATAL.
994 LogMessage(const char* file, int line, const char* condition);
995
[email protected]bf8ddf13a2014-06-18 15:02:22996 // Used for CHECK_EQ(), etc. Takes ownership of the given string.
997 // Implied severity = LOG_FATAL.
[email protected]9c7132e2011-02-08 07:39:08998 LogMessage(const char* file, int line, std::string* result);
initial.commitd7cae122008-07-26 21:49:38999
[email protected]bf8ddf13a2014-06-18 15:02:221000 // Used for DCHECK_EQ(), etc. Takes ownership of the given string.
[email protected]fb62a532009-02-12 01:19:051001 LogMessage(const char* file, int line, LogSeverity severity,
[email protected]9c7132e2011-02-08 07:39:081002 std::string* result);
[email protected]fb62a532009-02-12 01:19:051003
initial.commitd7cae122008-07-26 21:49:381004 ~LogMessage();
1005
1006 std::ostream& stream() { return stream_; }
1007
pastarmovj89f7ee12016-09-20 14:58:131008 LogSeverity severity() { return severity_; }
1009 std::string str() { return stream_.str(); }
1010
initial.commitd7cae122008-07-26 21:49:381011 private:
1012 void Init(const char* file, int line);
1013
1014 LogSeverity severity_;
1015 std::ostringstream stream_;
[email protected]c88873922008-07-30 13:02:031016 size_t message_start_; // Offset of the start of the message (past prefix
1017 // info).
[email protected]162ac0f2010-11-04 15:50:491018 // The file and line information passed in to the constructor.
1019 const char* file_;
1020 const int line_;
1021
[email protected]3f85caa2009-04-14 16:52:111022#if defined(OS_WIN)
1023 // Stores the current value of GetLastError in the constructor and restores
1024 // it in the destructor by calling SetLastError.
1025 // This is useful since the LogMessage class uses a lot of Win32 calls
1026 // that will lose the value of GLE and the code that called the log function
1027 // will have lost the thread error value when the log call returns.
1028 class SaveLastError {
1029 public:
1030 SaveLastError();
1031 ~SaveLastError();
1032
1033 unsigned long get_error() const { return last_error_; }
1034
1035 protected:
1036 unsigned long last_error_;
1037 };
1038
1039 SaveLastError last_error_;
1040#endif
initial.commitd7cae122008-07-26 21:49:381041
[email protected]39be4242008-08-07 18:31:401042 DISALLOW_COPY_AND_ASSIGN(LogMessage);
initial.commitd7cae122008-07-26 21:49:381043};
1044
initial.commitd7cae122008-07-26 21:49:381045// This class is used to explicitly ignore values in the conditional
1046// logging macros. This avoids compiler warnings like "value computed
1047// is not used" and "statement has no effect".
[email protected]23bb71f2011-04-21 22:22:101048class LogMessageVoidify {
initial.commitd7cae122008-07-26 21:49:381049 public:
Chris Watkins091d6292017-12-13 04:25:581050 LogMessageVoidify() = default;
initial.commitd7cae122008-07-26 21:49:381051 // This has to be an operator with a precedence lower than << but
1052 // higher than ?:
1053 void operator&(std::ostream&) { }
1054};
1055
[email protected]d8617a62009-10-09 23:52:201056#if defined(OS_WIN)
1057typedef unsigned long SystemErrorCode;
Fabrice de Gans-Riberi306871de2018-05-16 19:38:391058#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
[email protected]d8617a62009-10-09 23:52:201059typedef int SystemErrorCode;
1060#endif
1061
1062// Alias for ::GetLastError() on Windows and errno on POSIX. Avoids having to
1063// pull in windows.h just for GetLastError() and DWORD.
[email protected]0bea7252011-08-05 15:34:001064BASE_EXPORT SystemErrorCode GetLastSystemErrorCode();
[email protected]c914d8a2014-04-23 01:11:011065BASE_EXPORT std::string SystemErrorCodeToString(SystemErrorCode error_code);
[email protected]d8617a62009-10-09 23:52:201066
1067#if defined(OS_WIN)
1068// Appends a formatted system message of the GetLastError() type.
[email protected]0bea7252011-08-05 15:34:001069class BASE_EXPORT Win32ErrorLogMessage {
[email protected]d8617a62009-10-09 23:52:201070 public:
1071 Win32ErrorLogMessage(const char* file,
1072 int line,
1073 LogSeverity severity,
[email protected]d8617a62009-10-09 23:52:201074 SystemErrorCode err);
1075
[email protected]d8617a62009-10-09 23:52:201076 // Appends the error message before destructing the encapsulated class.
1077 ~Win32ErrorLogMessage();
1078
[email protected]a502bbe72011-01-07 18:06:451079 std::ostream& stream() { return log_message_.stream(); }
1080
[email protected]d8617a62009-10-09 23:52:201081 private:
1082 SystemErrorCode err_;
[email protected]d8617a62009-10-09 23:52:201083 LogMessage log_message_;
1084
1085 DISALLOW_COPY_AND_ASSIGN(Win32ErrorLogMessage);
1086};
Fabrice de Gans-Riberi306871de2018-05-16 19:38:391087#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
[email protected]d8617a62009-10-09 23:52:201088// Appends a formatted system message of the errno type
[email protected]0bea7252011-08-05 15:34:001089class BASE_EXPORT ErrnoLogMessage {
[email protected]d8617a62009-10-09 23:52:201090 public:
1091 ErrnoLogMessage(const char* file,
1092 int line,
1093 LogSeverity severity,
1094 SystemErrorCode err);
1095
[email protected]d8617a62009-10-09 23:52:201096 // Appends the error message before destructing the encapsulated class.
1097 ~ErrnoLogMessage();
1098
[email protected]a502bbe72011-01-07 18:06:451099 std::ostream& stream() { return log_message_.stream(); }
1100
[email protected]d8617a62009-10-09 23:52:201101 private:
1102 SystemErrorCode err_;
1103 LogMessage log_message_;
1104
1105 DISALLOW_COPY_AND_ASSIGN(ErrnoLogMessage);
1106};
1107#endif // OS_WIN
1108
initial.commitd7cae122008-07-26 21:49:381109// Closes the log file explicitly if open.
1110// NOTE: Since the log file is opened as necessary by the action of logging
1111// statements, there's no guarantee that it will stay closed
1112// after this call.
[email protected]0bea7252011-08-05 15:34:001113BASE_EXPORT void CloseLogFile();
initial.commitd7cae122008-07-26 21:49:381114
[email protected]e36ddc82009-12-08 04:22:501115// Async signal safe logging mechanism.
[email protected]0bea7252011-08-05 15:34:001116BASE_EXPORT void RawLog(int level, const char* message);
[email protected]e36ddc82009-12-08 04:22:501117
tsniatowski612550f2016-07-21 18:26:201118#define RAW_LOG(level, message) \
1119 ::logging::RawLog(::logging::LOG_##level, message)
[email protected]e36ddc82009-12-08 04:22:501120
tsniatowski612550f2016-07-21 18:26:201121#define RAW_CHECK(condition) \
1122 do { \
kmarshall08c892f72017-02-28 03:46:181123 if (!(condition)) \
tsniatowski612550f2016-07-21 18:26:201124 ::logging::RawLog(::logging::LOG_FATAL, \
1125 "Check failed: " #condition "\n"); \
[email protected]e36ddc82009-12-08 04:22:501126 } while (0)
1127
[email protected]f01b88a2013-02-27 22:04:001128#if defined(OS_WIN)
ananta61762fb2015-09-18 01:00:091129// Returns true if logging to file is enabled.
1130BASE_EXPORT bool IsLoggingToFileEnabled();
1131
[email protected]f01b88a2013-02-27 22:04:001132// Returns the default log file path.
1133BASE_EXPORT std::wstring GetLogFileFullPath();
1134#endif
1135
[email protected]39be4242008-08-07 18:31:401136} // namespace logging
initial.commitd7cae122008-07-26 21:49:381137
[email protected]81411c62014-07-08 23:03:061138// Note that "The behavior of a C++ program is undefined if it adds declarations
1139// or definitions to namespace std or to a namespace within namespace std unless
1140// otherwise specified." --C++11[namespace.std]
1141//
1142// We've checked that this particular definition has the intended behavior on
1143// our implementations, but it's prone to breaking in the future, and please
1144// don't imitate this in your own definitions without checking with some
1145// standard library experts.
1146namespace std {
[email protected]46ce5b562010-06-16 18:39:531147// These functions are provided as a convenience for logging, which is where we
1148// use streams (it is against Google style to use streams in other places). It
1149// is designed to allow you to emit non-ASCII Unicode strings to the log file,
1150// which is normally ASCII. It is relatively slow, so try not to use it for
1151// common cases. Non-ASCII characters will be converted to UTF-8 by these
1152// operators.
[email protected]0bea7252011-08-05 15:34:001153BASE_EXPORT std::ostream& operator<<(std::ostream& out, const wchar_t* wstr);
[email protected]46ce5b562010-06-16 18:39:531154inline std::ostream& operator<<(std::ostream& out, const std::wstring& wstr) {
1155 return out << wstr.c_str();
1156}
[email protected]81411c62014-07-08 23:03:061157} // namespace std
[email protected]46ce5b562010-06-16 18:39:531158
Daniel Bratellff541192017-11-02 14:22:281159// The NOTIMPLEMENTED() macro annotates codepaths which have not been
1160// implemented yet. If output spam is a serious concern,
1161// NOTIMPLEMENTED_LOG_ONCE can be used.
[email protected]0dfc81b2008-08-25 03:44:401162
[email protected]f6cda752008-10-30 23:54:261163#if defined(COMPILER_GCC)
1164// On Linux, with GCC, we can use __PRETTY_FUNCTION__ to get the demangled name
1165// of the current function in the NOTIMPLEMENTED message.
1166#define NOTIMPLEMENTED_MSG "Not implemented reached in " << __PRETTY_FUNCTION__
1167#else
1168#define NOTIMPLEMENTED_MSG "NOT IMPLEMENTED"
1169#endif
1170
Daniel Bratellff541192017-11-02 14:22:281171#if defined(OS_ANDROID) && defined(OFFICIAL_BUILD)
[email protected]38227292012-01-30 19:41:541172#define NOTIMPLEMENTED() EAT_STREAM_PARAMETERS
Daniel Bratellff541192017-11-02 14:22:281173#define NOTIMPLEMENTED_LOG_ONCE() EAT_STREAM_PARAMETERS
1174#else
[email protected]f6cda752008-10-30 23:54:261175#define NOTIMPLEMENTED() LOG(ERROR) << NOTIMPLEMENTED_MSG
Daniel Bratellff541192017-11-02 14:22:281176#define NOTIMPLEMENTED_LOG_ONCE() \
1177 do { \
1178 static bool logged_once = false; \
1179 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG; \
1180 logged_once = true; \
1181 } while (0); \
1182 EAT_STREAM_PARAMETERS
[email protected]0dfc81b2008-08-25 03:44:401183#endif
1184
[email protected]39be4242008-08-07 18:31:401185#endif // BASE_LOGGING_H_