blob: 386b8ba07dd5e1997a4370d6b93358c4bbcf28d2 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2// 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_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
initial.commitd7cae122008-07-26 21:49:388
9#include <string>
10#include <cstring>
11#include <sstream>
12
13#include "base/basictypes.h"
initial.commitd7cae122008-07-26 21:49:3814
15//
16// Optional message capabilities
17// -----------------------------
18// Assertion failed messages and fatal errors are displayed in a dialog box
19// before the application exits. However, running this UI creates a message
20// loop, which causes application messages to be processed and potentially
21// dispatched to existing application windows. Since the application is in a
22// bad state when this assertion dialog is displayed, these messages may not
23// get processed and hang the dialog, or the application might go crazy.
24//
25// Therefore, it can be beneficial to display the error dialog in a separate
26// process from the main application. When the logging system needs to display
27// a fatal error dialog box, it will look for a program called
28// "DebugMessage.exe" in the same directory as the application executable. It
29// will run this application with the message as the command line, and will
30// not include the name of the application as is traditional for easier
31// parsing.
32//
33// The code for DebugMessage.exe is only one line. In WinMain, do:
34// MessageBox(NULL, GetCommandLineW(), L"Fatal Error", 0);
35//
36// If DebugMessage.exe is not found, the logging code will use a normal
37// MessageBox, potentially causing the problems discussed above.
38
39
40// Instructions
41// ------------
42//
43// Make a bunch of macros for logging. The way to log things is to stream
44// things to LOG(<a particular severity level>). E.g.,
45//
46// LOG(INFO) << "Found " << num_cookies << " cookies";
47//
48// You can also do conditional logging:
49//
50// LOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
51//
52// The above will cause log messages to be output on the 1st, 11th, 21st, ...
53// times it is executed. Note that the special COUNTER value is used to
54// identify which repetition is happening.
55//
56// The CHECK(condition) macro is active in both debug and release builds and
57// effectively performs a LOG(FATAL) which terminates the process and
58// generates a crashdump unless a debugger is attached.
59//
60// There are also "debug mode" logging macros like the ones above:
61//
62// DLOG(INFO) << "Found cookies";
63//
64// DLOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
65//
66// All "debug mode" logging is compiled away to nothing for non-debug mode
67// compiles. LOG_IF and development flags also work well together
68// because the code can be compiled away sometimes.
69//
70// We also have
71//
72// LOG_ASSERT(assertion);
73// DLOG_ASSERT(assertion);
74//
75// which is syntactic sugar for {,D}LOG_IF(FATAL, assert fails) << assertion;
76//
[email protected]99b7c57f2010-09-29 19:26:3677// There are "verbose level" logging macros. They look like
78//
79// VLOG(1) << "I'm printed when you run the program with --v=1 or more";
80// VLOG(2) << "I'm printed when you run the program with --v=2 or more";
81//
82// These always log at the INFO log level (when they log at all).
83// The verbose logging can also be turned on module-by-module. For instance,
84// --vmodule=profile=2,icon_loader=1,browser_*=3 --v=0
85// will cause:
86// a. VLOG(2) and lower messages to be printed from profile.{h,cc}
87// b. VLOG(1) and lower messages to be printed from icon_loader.{h,cc}
88// c. VLOG(3) and lower messages to be printed from files prefixed with
89// "browser"
90// d. VLOG(0) and lower messages to be printed from elsewhere
91//
92// The wildcarding functionality shown by (c) supports both '*' (match
93// 0 or more characters) and '?' (match any single character) wildcards.
94//
95// There's also VLOG_IS_ON(n) "verbose level" condition macro. To be used as
96//
97// if (VLOG_IS_ON(2)) {
98// // do some logging preparation and logging
99// // that can't be accomplished with just VLOG(2) << ...;
100// }
101//
102// There is also a VLOG_IF "verbose level" condition macro for sample
103// cases, when some extra computation and preparation for logs is not
104// needed.
105//
106// VLOG_IF(1, (size > 1024))
107// << "I'm printed when size is more than 1024 and when you run the "
108// "program with --v=1 or more";
109//
initial.commitd7cae122008-07-26 21:49:38110// We also override the standard 'assert' to use 'DLOG_ASSERT'.
111//
[email protected]d8617a62009-10-09 23:52:20112// Lastly, there is:
113//
114// PLOG(ERROR) << "Couldn't do foo";
115// DPLOG(ERROR) << "Couldn't do foo";
116// PLOG_IF(ERROR, cond) << "Couldn't do foo";
117// DPLOG_IF(ERROR, cond) << "Couldn't do foo";
118// PCHECK(condition) << "Couldn't do foo";
119// DPCHECK(condition) << "Couldn't do foo";
120//
121// which append the last system error to the message in string form (taken from
122// GetLastError() on Windows and errno on POSIX).
123//
initial.commitd7cae122008-07-26 21:49:38124// The supported severity levels for macros that allow you to specify one
[email protected]fb62a532009-02-12 01:19:05125// are (in increasing order of severity) INFO, WARNING, ERROR, ERROR_REPORT,
126// and FATAL.
initial.commitd7cae122008-07-26 21:49:38127//
128// Very important: logging a message at the FATAL severity level causes
129// the program to terminate (after the message is logged).
[email protected]fb62a532009-02-12 01:19:05130//
131// Note the special severity of ERROR_REPORT only available/relevant in normal
132// mode, which displays error dialog without terminating the program. There is
133// no error dialog for severity ERROR or below in normal mode.
134//
135// There is also the special severity of DFATAL, which logs FATAL in
[email protected]081bd4c2010-06-24 01:01:04136// debug mode, ERROR in normal mode.
initial.commitd7cae122008-07-26 21:49:38137
138namespace logging {
139
140// Where to record logging output? A flat file and/or system debug log via
[email protected]88aa41e82008-11-18 00:59:04141// OutputDebugString. Defaults on Windows to LOG_ONLY_TO_FILE, and on
142// POSIX to LOG_ONLY_TO_SYSTEM_DEBUG_LOG (aka stderr).
initial.commitd7cae122008-07-26 21:49:38143enum LoggingDestination { LOG_NONE,
144 LOG_ONLY_TO_FILE,
145 LOG_ONLY_TO_SYSTEM_DEBUG_LOG,
146 LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG };
147
148// Indicates that the log file should be locked when being written to.
149// Often, there is no locking, which is fine for a single threaded program.
150// If logging is being done from multiple threads or there can be more than
151// one process doing the logging, the file should be locked during writes to
152// make each log outut atomic. Other writers will block.
153//
154// All processes writing to the log file must have their locking set for it to
155// work properly. Defaults to DONT_LOCK_LOG_FILE.
156enum LogLockingState { LOCK_LOG_FILE, DONT_LOCK_LOG_FILE };
157
158// On startup, should we delete or append to an existing log file (if any)?
159// Defaults to APPEND_TO_OLD_LOG_FILE.
160enum OldFileDeletionState { DELETE_OLD_LOG_FILE, APPEND_TO_OLD_LOG_FILE };
161
[email protected]ff3d0c32010-08-23 19:57:46162// TODO(avi): do we want to do a unification of character types here?
163#if defined(OS_WIN)
164typedef wchar_t PathChar;
165#else
166typedef char PathChar;
167#endif
168
169// Define different names for the BaseInitLoggingImpl() function depending on
170// whether NDEBUG is defined or not so that we'll fail to link if someone tries
171// to compile logging.cc with NDEBUG but includes logging.h without defining it,
172// or vice versa.
173#if NDEBUG
174#define BaseInitLoggingImpl BaseInitLoggingImpl_built_with_NDEBUG
175#else
176#define BaseInitLoggingImpl BaseInitLoggingImpl_built_without_NDEBUG
177#endif
178
179// Implementation of the InitLogging() method declared below. We use a
180// more-specific name so we can #define it above without affecting other code
181// that has named stuff "InitLogging".
182void BaseInitLoggingImpl(const PathChar* log_file,
183 LoggingDestination logging_dest,
184 LogLockingState lock_log,
185 OldFileDeletionState delete_old);
186
initial.commitd7cae122008-07-26 21:49:38187// Sets the log file name and other global logging state. Calling this function
188// is recommended, and is normally done at the beginning of application init.
189// If you don't call it, all the flags will be initialized to their default
190// values, and there is a race condition that may leak a critical section
191// object if two threads try to do the first log at the same time.
192// See the definition of the enums above for descriptions and default values.
193//
194// The default log file is initialized to "debug.log" in the application
195// directory. You probably don't want this, especially since the program
196// directory may not be writable on an enduser's system.
[email protected]ff3d0c32010-08-23 19:57:46197inline void InitLogging(const PathChar* log_file,
198 LoggingDestination logging_dest,
199 LogLockingState lock_log,
200 OldFileDeletionState delete_old) {
201 BaseInitLoggingImpl(log_file, logging_dest, lock_log, delete_old);
202}
initial.commitd7cae122008-07-26 21:49:38203
204// Sets the log level. Anything at or above this level will be written to the
205// log file/displayed to the user (if applicable). Anything below this level
206// will be silently ignored. The log level defaults to 0 (everything is logged)
207// if this function is not called.
208void SetMinLogLevel(int level);
209
[email protected]8a2986ca2009-04-10 19:13:42210// Gets the current log level.
initial.commitd7cae122008-07-26 21:49:38211int GetMinLogLevel();
212
[email protected]99b7c57f2010-09-29 19:26:36213// Gets the current vlog level for the given file (usually taken from
214// __FILE__).
[email protected]2f4e9a62010-09-29 21:25:14215
216// Note that |N| is the size *with* the null terminator.
217int GetVlogLevelHelper(const char* file_start, size_t N);
218
[email protected]99b7c57f2010-09-29 19:26:36219template <size_t N>
220int GetVlogLevel(const char (&file)[N]) {
221 return GetVlogLevelHelper(file, N);
222}
initial.commitd7cae122008-07-26 21:49:38223
224// Sets the common items you want to be prepended to each log message.
225// process and thread IDs default to off, the timestamp defaults to on.
226// If this function is not called, logging defaults to writing the timestamp
227// only.
228void SetLogItems(bool enable_process_id, bool enable_thread_id,
229 bool enable_timestamp, bool enable_tickcount);
230
[email protected]81e0a852010-08-17 00:38:12231// Sets whether or not you'd like to see fatal debug messages popped up in
232// a dialog box or not.
233// Dialogs are not shown by default.
234void SetShowErrorDialogs(bool enable_dialogs);
235
initial.commitd7cae122008-07-26 21:49:38236// Sets the Log Assert Handler that will be used to notify of check failures.
[email protected]fb62a532009-02-12 01:19:05237// The default handler shows a dialog box and then terminate the process,
238// however clients can use this function to override with their own handling
239// (e.g. a silent one for Unit Tests)
initial.commitd7cae122008-07-26 21:49:38240typedef void (*LogAssertHandlerFunction)(const std::string& str);
241void SetLogAssertHandler(LogAssertHandlerFunction handler);
[email protected]fb62a532009-02-12 01:19:05242// Sets the Log Report Handler that will be used to notify of check failures
243// in non-debug mode. The default handler shows a dialog box and continues
244// the execution, however clients can use this function to override with their
245// own handling.
246typedef void (*LogReportHandlerFunction)(const std::string& str);
247void SetLogReportHandler(LogReportHandlerFunction handler);
initial.commitd7cae122008-07-26 21:49:38248
[email protected]2b07b8412009-11-25 15:26:34249// Sets the Log Message Handler that gets passed every log message before
250// it's sent to other log destinations (if any).
251// Returns true to signal that it handled the message and the message
252// should not be sent to other log destinations.
253typedef bool (*LogMessageHandlerFunction)(int severity, const std::string& str);
254void SetLogMessageHandler(LogMessageHandlerFunction handler);
255
initial.commitd7cae122008-07-26 21:49:38256typedef int LogSeverity;
257const LogSeverity LOG_INFO = 0;
258const LogSeverity LOG_WARNING = 1;
259const LogSeverity LOG_ERROR = 2;
[email protected]fb62a532009-02-12 01:19:05260const LogSeverity LOG_ERROR_REPORT = 3;
261const LogSeverity LOG_FATAL = 4;
262const LogSeverity LOG_NUM_SEVERITIES = 5;
initial.commitd7cae122008-07-26 21:49:38263
[email protected]8b782102010-09-30 22:38:30264// LOG_DFATAL_LEVEL is LOG_FATAL in debug mode, ERROR in normal mode
initial.commitd7cae122008-07-26 21:49:38265#ifdef NDEBUG
[email protected]8b782102010-09-30 22:38:30266const LogSeverity LOG_DFATAL_LEVEL = LOG_ERROR;
initial.commitd7cae122008-07-26 21:49:38267#else
[email protected]8b782102010-09-30 22:38:30268const LogSeverity LOG_DFATAL_LEVEL = LOG_FATAL;
initial.commitd7cae122008-07-26 21:49:38269#endif
270
271// A few definitions of macros that don't generate much code. These are used
272// by LOG() and LOG_IF, etc. Since these are used all over our code, it's
273// better to have compact code for these operations.
[email protected]d8617a62009-10-09 23:52:20274#define COMPACT_GOOGLE_LOG_EX_INFO(ClassName, ...) \
275 logging::ClassName(__FILE__, __LINE__, logging::LOG_INFO , ##__VA_ARGS__)
276#define COMPACT_GOOGLE_LOG_EX_WARNING(ClassName, ...) \
277 logging::ClassName(__FILE__, __LINE__, logging::LOG_WARNING , ##__VA_ARGS__)
278#define COMPACT_GOOGLE_LOG_EX_ERROR(ClassName, ...) \
279 logging::ClassName(__FILE__, __LINE__, logging::LOG_ERROR , ##__VA_ARGS__)
280#define COMPACT_GOOGLE_LOG_EX_ERROR_REPORT(ClassName, ...) \
281 logging::ClassName(__FILE__, __LINE__, \
282 logging::LOG_ERROR_REPORT , ##__VA_ARGS__)
283#define COMPACT_GOOGLE_LOG_EX_FATAL(ClassName, ...) \
284 logging::ClassName(__FILE__, __LINE__, logging::LOG_FATAL , ##__VA_ARGS__)
285#define COMPACT_GOOGLE_LOG_EX_DFATAL(ClassName, ...) \
[email protected]8b782102010-09-30 22:38:30286 logging::ClassName(__FILE__, __LINE__, \
287 logging::LOG_DFATAL_LEVEL , ##__VA_ARGS__)
[email protected]d8617a62009-10-09 23:52:20288
initial.commitd7cae122008-07-26 21:49:38289#define COMPACT_GOOGLE_LOG_INFO \
[email protected]d8617a62009-10-09 23:52:20290 COMPACT_GOOGLE_LOG_EX_INFO(LogMessage)
initial.commitd7cae122008-07-26 21:49:38291#define COMPACT_GOOGLE_LOG_WARNING \
[email protected]d8617a62009-10-09 23:52:20292 COMPACT_GOOGLE_LOG_EX_WARNING(LogMessage)
initial.commitd7cae122008-07-26 21:49:38293#define COMPACT_GOOGLE_LOG_ERROR \
[email protected]d8617a62009-10-09 23:52:20294 COMPACT_GOOGLE_LOG_EX_ERROR(LogMessage)
[email protected]fb62a532009-02-12 01:19:05295#define COMPACT_GOOGLE_LOG_ERROR_REPORT \
[email protected]d8617a62009-10-09 23:52:20296 COMPACT_GOOGLE_LOG_EX_ERROR_REPORT(LogMessage)
initial.commitd7cae122008-07-26 21:49:38297#define COMPACT_GOOGLE_LOG_FATAL \
[email protected]d8617a62009-10-09 23:52:20298 COMPACT_GOOGLE_LOG_EX_FATAL(LogMessage)
initial.commitd7cae122008-07-26 21:49:38299#define COMPACT_GOOGLE_LOG_DFATAL \
[email protected]d8617a62009-10-09 23:52:20300 COMPACT_GOOGLE_LOG_EX_DFATAL(LogMessage)
initial.commitd7cae122008-07-26 21:49:38301
302// wingdi.h defines ERROR to be 0. When we call LOG(ERROR), it gets
303// substituted with 0, and it expands to COMPACT_GOOGLE_LOG_0. To allow us
304// to keep using this syntax, we define this macro to do the same thing
305// as COMPACT_GOOGLE_LOG_ERROR, and also define ERROR the same way that
306// the Windows SDK does for consistency.
307#define ERROR 0
[email protected]d8617a62009-10-09 23:52:20308#define COMPACT_GOOGLE_LOG_EX_0(ClassName, ...) \
309 COMPACT_GOOGLE_LOG_EX_ERROR(ClassName , ##__VA_ARGS__)
310#define COMPACT_GOOGLE_LOG_0 COMPACT_GOOGLE_LOG_ERROR
initial.commitd7cae122008-07-26 21:49:38311
312// We use the preprocessor's merging operator, "##", so that, e.g.,
313// LOG(INFO) becomes the token COMPACT_GOOGLE_LOG_INFO. There's some funny
314// subtle difference between ostream member streaming functions (e.g.,
315// ostream::operator<<(int) and ostream non-member streaming functions
316// (e.g., ::operator<<(ostream&, string&): it turns out that it's
317// impossible to stream something like a string directly to an unnamed
318// ostream. We employ a neat hack by calling the stream() member
319// function of LogMessage which seems to avoid the problem.
[email protected]8b782102010-09-30 22:38:30320//
321// We can't do any caching tricks with VLOG_IS_ON() like the
322// google-glog version since it requires GCC extensions. This means
323// that using the v-logging functions in conjunction with --vmodule
324// may be slow.
325#define VLOG_IS_ON(verboselevel) \
326 (logging::GetVlogLevel(__FILE__) >= (verboselevel))
initial.commitd7cae122008-07-26 21:49:38327
[email protected]8b782102010-09-30 22:38:30328#define LOG(severity) COMPACT_GOOGLE_LOG_ ## severity.stream()
initial.commitd7cae122008-07-26 21:49:38329#define SYSLOG(severity) LOG(severity)
[email protected]99b7c57f2010-09-29 19:26:36330#define VLOG(verboselevel) LOG_IF(INFO, VLOG_IS_ON(verboselevel))
331
332// TODO(akalin): Add more VLOG variants, e.g. VPLOG.
initial.commitd7cae122008-07-26 21:49:38333
[email protected]8b782102010-09-30 22:38:30334#define LOG_IF(severity, condition) \
335 !(condition) ? (void) 0 : logging::LogMessageVoidify() & LOG(severity)
336#define SYSLOG_IF(severity, condition) LOG_IF(severity, condition)
337#define VLOG_IF(verboselevel, condition) \
338 LOG_IF(INFO, (condition) && VLOG_IS_ON(verboselevel))
339
initial.commitd7cae122008-07-26 21:49:38340#define LOG_ASSERT(condition) \
341 LOG_IF(FATAL, !(condition)) << "Assert failed: " #condition ". "
342#define SYSLOG_ASSERT(condition) \
343 SYSLOG_IF(FATAL, !(condition)) << "Assert failed: " #condition ". "
344
[email protected]d8617a62009-10-09 23:52:20345#if defined(OS_WIN)
[email protected]8b782102010-09-30 22:38:30346#define LOG_GETLASTERROR(severity) \
[email protected]d8617a62009-10-09 23:52:20347 COMPACT_GOOGLE_LOG_EX_ ## severity(Win32ErrorLogMessage, \
348 ::logging::GetLastSystemErrorCode()).stream()
[email protected]8b782102010-09-30 22:38:30349#define LOG_GETLASTERROR_MODULE(severity, module) \
[email protected]d8617a62009-10-09 23:52:20350 COMPACT_GOOGLE_LOG_EX_ ## severity(Win32ErrorLogMessage, \
351 ::logging::GetLastSystemErrorCode(), module).stream()
[email protected]8b782102010-09-30 22:38:30352// PLOG is the usual error logging macro for each platform.
353#define PLOG(severity) LOG_GETLASTERROR(severity)
354#define DPLOG(severity) DLOG_GETLASTERROR(severity)
[email protected]d8617a62009-10-09 23:52:20355#elif defined(OS_POSIX)
[email protected]8b782102010-09-30 22:38:30356#define LOG_ERRNO(severity) \
[email protected]d8617a62009-10-09 23:52:20357 COMPACT_GOOGLE_LOG_EX_ ## severity(ErrnoLogMessage, \
358 ::logging::GetLastSystemErrorCode()).stream()
[email protected]8b782102010-09-30 22:38:30359// PLOG is the usual error logging macro for each platform.
360#define PLOG(severity) LOG_ERRNO(severity)
361#define DPLOG(severity) DLOG_ERRNO(severity)
[email protected]d8617a62009-10-09 23:52:20362// TODO(tschmelcher): Should we add OSStatus logging for Mac?
363#endif
364
365#define PLOG_IF(severity, condition) \
[email protected]8b782102010-09-30 22:38:30366 !(condition) ? (void) 0 : logging::LogMessageVoidify() & PLOG(severity)
[email protected]d8617a62009-10-09 23:52:20367
initial.commitd7cae122008-07-26 21:49:38368// CHECK dies with a fatal error if condition is not true. It is *not*
369// controlled by NDEBUG, so the check will be executed regardless of
370// compilation mode.
371#define CHECK(condition) \
372 LOG_IF(FATAL, !(condition)) << "Check failed: " #condition ". "
373
[email protected]d8617a62009-10-09 23:52:20374#define PCHECK(condition) \
375 PLOG_IF(FATAL, !(condition)) << "Check failed: " #condition ". "
376
initial.commitd7cae122008-07-26 21:49:38377// A container for a string pointer which can be evaluated to a bool -
378// true iff the pointer is NULL.
379struct CheckOpString {
380 CheckOpString(std::string* str) : str_(str) { }
381 // No destructor: if str_ is non-NULL, we're about to LOG(FATAL),
382 // so there's no point in cleaning up str_.
383 operator bool() const { return str_ != NULL; }
384 std::string* str_;
385};
386
387// Build the error message string. This is separate from the "Impl"
388// function template because it is not performance critical and so can
389// be out of line, while the "Impl" code should be inline.
390template<class t1, class t2>
391std::string* MakeCheckOpString(const t1& v1, const t2& v2, const char* names) {
392 std::ostringstream ss;
393 ss << names << " (" << v1 << " vs. " << v2 << ")";
394 std::string* msg = new std::string(ss.str());
395 return msg;
396}
397
[email protected]6d445d32010-09-30 19:10:03398// MSVC doesn't like complex extern templates and DLLs.
399#if !defined(COMPILER_MSVC)
400// Commonly used instantiations of MakeCheckOpString<>. Explicitly instantiated
401// in logging.cc.
402extern template std::string* MakeCheckOpString<int, int>(
403 const int&, const int&, const char* names);
404extern template std::string* MakeCheckOpString<unsigned long, unsigned long>(
405 const unsigned long&, const unsigned long&, const char* names);
406extern template std::string* MakeCheckOpString<unsigned long, unsigned int>(
407 const unsigned long&, const unsigned int&, const char* names);
408extern template std::string* MakeCheckOpString<unsigned int, unsigned long>(
409 const unsigned int&, const unsigned long&, const char* names);
410extern template std::string* MakeCheckOpString<std::string, std::string>(
411 const std::string&, const std::string&, const char* name);
412#endif
initial.commitd7cae122008-07-26 21:49:38413
[email protected]e150c0382010-03-02 00:41:12414// Helper macro for binary operators.
415// Don't use this macro directly in your code, use CHECK_EQ et al below.
[email protected]8b782102010-09-30 22:38:30416#define CHECK_OP(name, op, val1, val2) \
417 if (logging::CheckOpString _result = \
418 logging::Check##name##Impl((val1), (val2), #val1 " " #op " " #val2)) \
419 logging::LogMessage(__FILE__, __LINE__, _result).stream()
[email protected]e150c0382010-03-02 00:41:12420
421// Helper functions for string comparisons.
422// To avoid bloat, the definitions are in logging.cc.
423#define DECLARE_CHECK_STROP_IMPL(func, expected) \
424 std::string* Check##func##expected##Impl(const char* s1, \
425 const char* s2, \
426 const char* names);
427DECLARE_CHECK_STROP_IMPL(strcmp, true)
428DECLARE_CHECK_STROP_IMPL(strcmp, false)
429DECLARE_CHECK_STROP_IMPL(_stricmp, true)
430DECLARE_CHECK_STROP_IMPL(_stricmp, false)
431#undef DECLARE_CHECK_STROP_IMPL
432
433// Helper macro for string comparisons.
434// Don't use this macro directly in your code, use CHECK_STREQ et al below.
435#define CHECK_STROP(func, op, expected, s1, s2) \
436 while (CheckOpString _result = \
437 logging::Check##func##expected##Impl((s1), (s2), \
438 #s1 " " #op " " #s2)) \
439 LOG(FATAL) << *_result.str_
440
441// String (char*) equality/inequality checks.
442// CASE versions are case-insensitive.
443//
444// Note that "s1" and "s2" may be temporary strings which are destroyed
445// by the compiler at the end of the current "full expression"
446// (e.g. CHECK_STREQ(Foo().c_str(), Bar().c_str())).
447
448#define CHECK_STREQ(s1, s2) CHECK_STROP(strcmp, ==, true, s1, s2)
449#define CHECK_STRNE(s1, s2) CHECK_STROP(strcmp, !=, false, s1, s2)
450#define CHECK_STRCASEEQ(s1, s2) CHECK_STROP(_stricmp, ==, true, s1, s2)
451#define CHECK_STRCASENE(s1, s2) CHECK_STROP(_stricmp, !=, false, s1, s2)
452
453#define CHECK_INDEX(I,A) CHECK(I < (sizeof(A)/sizeof(A[0])))
454#define CHECK_BOUND(B,A) CHECK(B <= (sizeof(A)/sizeof(A[0])))
455
456#define CHECK_EQ(val1, val2) CHECK_OP(EQ, ==, val1, val2)
457#define CHECK_NE(val1, val2) CHECK_OP(NE, !=, val1, val2)
458#define CHECK_LE(val1, val2) CHECK_OP(LE, <=, val1, val2)
459#define CHECK_LT(val1, val2) CHECK_OP(LT, < , val1, val2)
460#define CHECK_GE(val1, val2) CHECK_OP(GE, >=, val1, val2)
461#define CHECK_GT(val1, val2) CHECK_OP(GT, > , val1, val2)
462
[email protected]e3cca332009-08-20 01:20:29463// http://crbug.com/16512 is open for a real fix for this. For now, Windows
464// uses OFFICIAL_BUILD and other platforms use the branding flag when NDEBUG is
465// defined.
466#if ( defined(OS_WIN) && defined(OFFICIAL_BUILD)) || \
467 (!defined(OS_WIN) && defined(NDEBUG) && defined(GOOGLE_CHROME_BUILD))
468// In order to have optimized code for official builds, remove DLOGs and
469// DCHECKs.
[email protected]d15e56c2010-09-30 21:12:33470#define ENABLE_DLOG 0
471#define ENABLE_DCHECK 0
472
473#elif defined(NDEBUG)
474// Otherwise, if we're a release build, remove DLOGs but not DCHECKs
475// (since those can still be turned on via a command-line flag).
476#define ENABLE_DLOG 0
477#define ENABLE_DCHECK 1
478
479#else
480// Otherwise, we're a debug build so enable DLOGs and DCHECKs.
481#define ENABLE_DLOG 1
482#define ENABLE_DCHECK 1
[email protected]e3cca332009-08-20 01:20:29483#endif
484
[email protected]d15e56c2010-09-30 21:12:33485// Definitions for DLOG et al.
486
[email protected]8b782102010-09-30 22:38:30487#if ENABLE_DLOG
488
489#define DLOG(severity) LOG(severity)
490#define DLOG_IF(severity, condition) LOG_IF(severity, condition)
491#define DLOG_ASSERT(condition) LOG_ASSERT(condition)
492
493#if defined(OS_WIN)
494#define DLOG_GETLASTERROR(severity) LOG_GETLASTERROR(severity)
495#define DLOG_GETLASTERROR_MODULE(severity, module) \
496 LOG_GETLASTERROR_MODULE(severity, module)
497#elif defined(OS_POSIX)
498#define DLOG_ERRNO(severity) LOG_ERRNO(severity)
499#endif
500
501#define DPLOG_IF(severity, condition) PLOG_IF(severity, condition)
502
503#else // ENABLE_DLOG
504
505#define DLOG(severity) \
506 true ? (void) 0 : logging::LogMessageVoidify() & LOG(severity)
507
508#define DLOG_IF(severity, condition) \
509 true ? (void) 0 : logging::LogMessageVoidify() & LOG(severity)
510
511#define DLOG_ASSERT(condition) \
512 true ? (void) 0 : LOG_ASSERT(condition)
513
514#if defined(OS_WIN)
515#define DLOG_GETLASTERROR(severity) \
516 true ? (void) 0 : logging::LogMessageVoidify() & LOG_GETLASTERROR(severity)
517#define DLOG_GETLASTERROR_MODULE(severity, module) \
518 true ? (void) 0 : logging::LogMessageVoidify() & \
519 LOG_GETLASTERROR_MODULE(severity, module)
520#elif defined(OS_POSIX)
521#define DLOG_ERRNO(severity) \
522 true ? (void) 0 : logging::LogMessageVoidify() & LOG_ERRNO(severity)
523#endif
524
525#define DPLOG_IF(severity, condition) \
526 true ? (void) 0 : logging::LogMessageVoidify() & PLOG(severity)
527
528#endif // ENABLE_DLOG
529
[email protected]d15e56c2010-09-30 21:12:33530// DEBUG_MODE is for uses like
531// if (DEBUG_MODE) foo.CheckThatFoo();
532// instead of
533// #ifndef NDEBUG
534// foo.CheckThatFoo();
535// #endif
536//
537// We tie its state to ENABLE_DLOG.
538enum { DEBUG_MODE = ENABLE_DLOG };
539
540#undef ENABLE_DLOG
541
[email protected]f2235532010-09-30 22:26:41542// Definitions for DCHECK et al.
[email protected]94558e632008-12-11 22:10:17543
[email protected]8b782102010-09-30 22:38:30544// This macro can be followed by a sequence of stream parameters in
545// non-debug mode. The DCHECK and friends macros use this so that
546// the expanded expression DCHECK(foo) << "asdf" is still syntactically
547// valid, even though the expression will get optimized away.
548#define DCHECK_EAT_STREAM_PARAMETERS \
549 logging::LogMessage(__FILE__, __LINE__).stream()
550
[email protected]d15e56c2010-09-30 21:12:33551#if ENABLE_DCHECK
[email protected]e3cca332009-08-20 01:20:29552
[email protected]8b782102010-09-30 22:38:30553#ifndef NDEBUG
[email protected]f2235532010-09-30 22:26:41554// On a regular debug build, we want to have DCHECKS enabled.
[email protected]f2235532010-09-30 22:26:41555
[email protected]8b782102010-09-30 22:38:30556#define DCHECK(condition) CHECK(condition)
557#define DPCHECK(condition) PCHECK(condition)
[email protected]d8617a62009-10-09 23:52:20558
initial.commitd7cae122008-07-26 21:49:38559// Helper macro for binary operators.
560// Don't use this macro directly in your code, use DCHECK_EQ et al below.
[email protected]8b782102010-09-30 22:38:30561#define DCHECK_OP(name, op, val1, val2) \
562 if (logging::CheckOpString _result = \
563 logging::Check##name##Impl((val1), (val2), #val1 " " #op " " #val2)) \
564 logging::LogMessage(__FILE__, __LINE__, _result).stream()
565
566// Helper macro for string comparisons.
567// Don't use this macro directly in your code, use CHECK_STREQ et al below.
568#define DCHECK_STROP(func, op, expected, s1, s2) \
569 while (CheckOpString _result = \
570 logging::Check##func##expected##Impl((s1), (s2), \
571 #s1 " " #op " " #s2)) \
572 LOG(FATAL) << *_result.str_
573
574// String (char*) equality/inequality checks.
575// CASE versions are case-insensitive.
576//
577// Note that "s1" and "s2" may be temporary strings which are destroyed
578// by the compiler at the end of the current "full expression"
579// (e.g. DCHECK_STREQ(Foo().c_str(), Bar().c_str())).
580
581#define DCHECK_STREQ(s1, s2) DCHECK_STROP(strcmp, ==, true, s1, s2)
582#define DCHECK_STRNE(s1, s2) DCHECK_STROP(strcmp, !=, false, s1, s2)
583#define DCHECK_STRCASEEQ(s1, s2) DCHECK_STROP(_stricmp, ==, true, s1, s2)
584#define DCHECK_STRCASENE(s1, s2) DCHECK_STROP(_stricmp, !=, false, s1, s2)
585
586#define DCHECK_INDEX(I,A) DCHECK(I < (sizeof(A)/sizeof(A[0])))
587#define DCHECK_BOUND(B,A) DCHECK(B <= (sizeof(A)/sizeof(A[0])))
588
589#else // NDEBUG
590// On a regular release build we want to be able to enable DCHECKS through the
591// command line.
592
593// Set to true in InitLogging when we want to enable the dchecks in release.
594extern bool g_enable_dcheck;
595#define DCHECK(condition) \
596 !logging::g_enable_dcheck ? void (0) : \
597 LOG_IF(ERROR_REPORT, !(condition)) << "Check failed: " #condition ". "
598
599#define DPCHECK(condition) \
600 !logging::g_enable_dcheck ? void (0) : \
601 PLOG_IF(ERROR_REPORT, !(condition)) << "Check failed: " #condition ". "
602
603// Helper macro for binary operators.
604// Don't use this macro directly in your code, use DCHECK_EQ et al below.
605#define DCHECK_OP(name, op, val1, val2) \
606 if (logging::g_enable_dcheck) \
607 if (logging::CheckOpString _result = \
608 logging::Check##name##Impl((val1), (val2), #val1 " " #op " " #val2)) \
609 logging::LogMessage(__FILE__, __LINE__, logging::LOG_ERROR_REPORT, \
610 _result).stream()
611
612#define DCHECK_STREQ(str1, str2) \
613 while (false) DCHECK_EAT_STREAM_PARAMETERS
614
615#define DCHECK_STRCASEEQ(str1, str2) \
616 while (false) DCHECK_EAT_STREAM_PARAMETERS
617
618#define DCHECK_STRNE(str1, str2) \
619 while (false) DCHECK_EAT_STREAM_PARAMETERS
620
621#define DCHECK_STRCASENE(str1, str2) \
622 while (false) DCHECK_EAT_STREAM_PARAMETERS
623
624#endif // NDEBUG
initial.commitd7cae122008-07-26 21:49:38625
initial.commitd7cae122008-07-26 21:49:38626// Equality/Inequality checks - compare two values, and log a LOG_FATAL message
627// including the two values when the result is not as expected. The values
628// must have operator<<(ostream, ...) defined.
629//
630// You may append to the error message like so:
631// DCHECK_NE(1, 2) << ": The world must be ending!";
632//
633// We are very careful to ensure that each argument is evaluated exactly
634// once, and that anything which is legal to pass as a function argument is
635// legal here. In particular, the arguments may be temporary expressions
636// which will end up being destroyed at the end of the apparent statement,
637// for example:
638// DCHECK_EQ(string("abc")[1], 'b');
639//
640// WARNING: These may not compile correctly if one of the arguments is a pointer
641// and the other is NULL. To work around this, simply static_cast NULL to the
642// type of the desired pointer.
643
644#define DCHECK_EQ(val1, val2) DCHECK_OP(EQ, ==, val1, val2)
645#define DCHECK_NE(val1, val2) DCHECK_OP(NE, !=, val1, val2)
646#define DCHECK_LE(val1, val2) DCHECK_OP(LE, <=, val1, val2)
647#define DCHECK_LT(val1, val2) DCHECK_OP(LT, < , val1, val2)
648#define DCHECK_GE(val1, val2) DCHECK_OP(GE, >=, val1, val2)
649#define DCHECK_GT(val1, val2) DCHECK_OP(GT, > , val1, val2)
650
[email protected]8b782102010-09-30 22:38:30651#else // ENABLE_DCHECK
initial.commitd7cae122008-07-26 21:49:38652
[email protected]8b782102010-09-30 22:38:30653// In order to avoid variable unused warnings for code that only uses a
654// variable in a CHECK, we make sure to use the macro arguments.
[email protected]d15e56c2010-09-30 21:12:33655
[email protected]8b782102010-09-30 22:38:30656#define DCHECK(condition) \
657 while (false && (condition)) DCHECK_EAT_STREAM_PARAMETERS
[email protected]d15e56c2010-09-30 21:12:33658
[email protected]8b782102010-09-30 22:38:30659#define DPCHECK(condition) \
660 while (false && (condition)) DCHECK_EAT_STREAM_PARAMETERS
661
662#define DCHECK_EQ(val1, val2) \
663 while (false && (val1) == (val2)) DCHECK_EAT_STREAM_PARAMETERS
664
665#define DCHECK_NE(val1, val2) \
666 while (false && (val1) == (val2)) DCHECK_EAT_STREAM_PARAMETERS
667
668#define DCHECK_LE(val1, val2) \
669 while (false && (val1) == (val2)) DCHECK_EAT_STREAM_PARAMETERS
670
671#define DCHECK_LT(val1, val2) \
672 while (false && (val1) == (val2)) DCHECK_EAT_STREAM_PARAMETERS
673
674#define DCHECK_GE(val1, val2) \
675 while (false && (val1) == (val2)) DCHECK_EAT_STREAM_PARAMETERS
676
677#define DCHECK_GT(val1, val2) \
678 while (false && (val1) == (val2)) DCHECK_EAT_STREAM_PARAMETERS
679
680#define DCHECK_STREQ(str1, str2) \
681 while (false && (str1) == (str2)) DCHECK_EAT_STREAM_PARAMETERS
682
683#define DCHECK_STRCASEEQ(str1, str2) \
684 while (false && (str1) == (str2)) DCHECK_EAT_STREAM_PARAMETERS
685
686#define DCHECK_STRNE(str1, str2) \
687 while (false && (str1) == (str2)) DCHECK_EAT_STREAM_PARAMETERS
688
689#define DCHECK_STRCASENE(str1, str2) \
690 while (false && (str1) == (str2)) DCHECK_EAT_STREAM_PARAMETERS
691
692#endif // ENABLE_DCHECK
693#undef ENABLE_DCHECK
694
695#undef DCHECK_EAT_STREAM_PARAMETERS
[email protected]e150c0382010-03-02 00:41:12696
697// Helper functions for CHECK_OP macro.
698// The (int, int) specialization works around the issue that the compiler
699// will not instantiate the template version of the function on values of
700// unnamed enum type - see comment below.
701#define DEFINE_CHECK_OP_IMPL(name, op) \
702 template <class t1, class t2> \
703 inline std::string* Check##name##Impl(const t1& v1, const t2& v2, \
704 const char* names) { \
705 if (v1 op v2) return NULL; \
706 else return MakeCheckOpString(v1, v2, names); \
707 } \
708 inline std::string* Check##name##Impl(int v1, int v2, const char* names) { \
709 if (v1 op v2) return NULL; \
710 else return MakeCheckOpString(v1, v2, names); \
711 }
712DEFINE_CHECK_OP_IMPL(EQ, ==)
713DEFINE_CHECK_OP_IMPL(NE, !=)
714DEFINE_CHECK_OP_IMPL(LE, <=)
715DEFINE_CHECK_OP_IMPL(LT, < )
716DEFINE_CHECK_OP_IMPL(GE, >=)
717DEFINE_CHECK_OP_IMPL(GT, > )
718#undef DEFINE_CHECK_OP_IMPL
719
initial.commitd7cae122008-07-26 21:49:38720#define NOTREACHED() DCHECK(false)
721
722// Redefine the standard assert to use our nice log files
723#undef assert
724#define assert(x) DLOG_ASSERT(x)
725
726// This class more or less represents a particular log message. You
727// create an instance of LogMessage and then stream stuff to it.
728// When you finish streaming to it, ~LogMessage is called and the
729// full message gets streamed to the appropriate destination.
730//
731// You shouldn't actually use LogMessage's constructor to log things,
732// though. You should use the LOG() macro (and variants thereof)
733// above.
734class LogMessage {
735 public:
736 LogMessage(const char* file, int line, LogSeverity severity, int ctr);
737
738 // Two special constructors that generate reduced amounts of code at
739 // LOG call sites for common cases.
740 //
741 // Used for LOG(INFO): Implied are:
742 // severity = LOG_INFO, ctr = 0
743 //
744 // Using this constructor instead of the more complex constructor above
745 // saves a couple of bytes per call site.
746 LogMessage(const char* file, int line);
747
748 // Used for LOG(severity) where severity != INFO. Implied
749 // are: ctr = 0
750 //
751 // Using this constructor instead of the more complex constructor above
752 // saves a couple of bytes per call site.
753 LogMessage(const char* file, int line, LogSeverity severity);
754
755 // A special constructor used for check failures.
756 // Implied severity = LOG_FATAL
757 LogMessage(const char* file, int line, const CheckOpString& result);
758
[email protected]fb62a532009-02-12 01:19:05759 // A special constructor used for check failures, with the option to
760 // specify severity.
761 LogMessage(const char* file, int line, LogSeverity severity,
762 const CheckOpString& result);
763
initial.commitd7cae122008-07-26 21:49:38764 ~LogMessage();
765
766 std::ostream& stream() { return stream_; }
767
768 private:
769 void Init(const char* file, int line);
770
771 LogSeverity severity_;
772 std::ostringstream stream_;
[email protected]c88873922008-07-30 13:02:03773 size_t message_start_; // Offset of the start of the message (past prefix
774 // info).
[email protected]3f85caa2009-04-14 16:52:11775#if defined(OS_WIN)
776 // Stores the current value of GetLastError in the constructor and restores
777 // it in the destructor by calling SetLastError.
778 // This is useful since the LogMessage class uses a lot of Win32 calls
779 // that will lose the value of GLE and the code that called the log function
780 // will have lost the thread error value when the log call returns.
781 class SaveLastError {
782 public:
783 SaveLastError();
784 ~SaveLastError();
785
786 unsigned long get_error() const { return last_error_; }
787
788 protected:
789 unsigned long last_error_;
790 };
791
792 SaveLastError last_error_;
793#endif
initial.commitd7cae122008-07-26 21:49:38794
[email protected]39be4242008-08-07 18:31:40795 DISALLOW_COPY_AND_ASSIGN(LogMessage);
initial.commitd7cae122008-07-26 21:49:38796};
797
798// A non-macro interface to the log facility; (useful
799// when the logging level is not a compile-time constant).
800inline void LogAtLevel(int const log_level, std::string const &msg) {
801 LogMessage(__FILE__, __LINE__, log_level).stream() << msg;
802}
803
804// This class is used to explicitly ignore values in the conditional
805// logging macros. This avoids compiler warnings like "value computed
806// is not used" and "statement has no effect".
807class LogMessageVoidify {
808 public:
809 LogMessageVoidify() { }
810 // This has to be an operator with a precedence lower than << but
811 // higher than ?:
812 void operator&(std::ostream&) { }
813};
814
[email protected]d8617a62009-10-09 23:52:20815#if defined(OS_WIN)
816typedef unsigned long SystemErrorCode;
817#elif defined(OS_POSIX)
818typedef int SystemErrorCode;
819#endif
820
821// Alias for ::GetLastError() on Windows and errno on POSIX. Avoids having to
822// pull in windows.h just for GetLastError() and DWORD.
823SystemErrorCode GetLastSystemErrorCode();
824
825#if defined(OS_WIN)
826// Appends a formatted system message of the GetLastError() type.
827class Win32ErrorLogMessage {
828 public:
829 Win32ErrorLogMessage(const char* file,
830 int line,
831 LogSeverity severity,
832 SystemErrorCode err,
833 const char* module);
834
835 Win32ErrorLogMessage(const char* file,
836 int line,
837 LogSeverity severity,
838 SystemErrorCode err);
839
840 std::ostream& stream() { return log_message_.stream(); }
841
842 // Appends the error message before destructing the encapsulated class.
843 ~Win32ErrorLogMessage();
844
845 private:
846 SystemErrorCode err_;
847 // Optional name of the module defining the error.
848 const char* module_;
849 LogMessage log_message_;
850
851 DISALLOW_COPY_AND_ASSIGN(Win32ErrorLogMessage);
852};
853#elif defined(OS_POSIX)
854// Appends a formatted system message of the errno type
855class ErrnoLogMessage {
856 public:
857 ErrnoLogMessage(const char* file,
858 int line,
859 LogSeverity severity,
860 SystemErrorCode err);
861
862 std::ostream& stream() { return log_message_.stream(); }
863
864 // Appends the error message before destructing the encapsulated class.
865 ~ErrnoLogMessage();
866
867 private:
868 SystemErrorCode err_;
869 LogMessage log_message_;
870
871 DISALLOW_COPY_AND_ASSIGN(ErrnoLogMessage);
872};
873#endif // OS_WIN
874
initial.commitd7cae122008-07-26 21:49:38875// Closes the log file explicitly if open.
876// NOTE: Since the log file is opened as necessary by the action of logging
877// statements, there's no guarantee that it will stay closed
878// after this call.
879void CloseLogFile();
880
[email protected]e36ddc82009-12-08 04:22:50881// Async signal safe logging mechanism.
882void RawLog(int level, const char* message);
883
884#define RAW_LOG(level, message) logging::RawLog(logging::LOG_ ## level, message)
885
886#define RAW_CHECK(condition) \
887 do { \
888 if (!(condition)) \
889 logging::RawLog(logging::LOG_FATAL, "Check failed: " #condition "\n"); \
890 } while (0)
891
[email protected]39be4242008-08-07 18:31:40892} // namespace logging
initial.commitd7cae122008-07-26 21:49:38893
[email protected]46ce5b562010-06-16 18:39:53894// These functions are provided as a convenience for logging, which is where we
895// use streams (it is against Google style to use streams in other places). It
896// is designed to allow you to emit non-ASCII Unicode strings to the log file,
897// which is normally ASCII. It is relatively slow, so try not to use it for
898// common cases. Non-ASCII characters will be converted to UTF-8 by these
899// operators.
900std::ostream& operator<<(std::ostream& out, const wchar_t* wstr);
901inline std::ostream& operator<<(std::ostream& out, const std::wstring& wstr) {
902 return out << wstr.c_str();
903}
904
[email protected]0dfc81b2008-08-25 03:44:40905// The NOTIMPLEMENTED() macro annotates codepaths which have
906// not been implemented yet.
907//
908// The implementation of this macro is controlled by NOTIMPLEMENTED_POLICY:
909// 0 -- Do nothing (stripped by compiler)
910// 1 -- Warn at compile time
911// 2 -- Fail at compile time
912// 3 -- Fail at runtime (DCHECK)
913// 4 -- [default] LOG(ERROR) at runtime
914// 5 -- LOG(ERROR) at runtime, only once per call-site
915
916#ifndef NOTIMPLEMENTED_POLICY
917// Select default policy: LOG(ERROR)
918#define NOTIMPLEMENTED_POLICY 4
919#endif
920
[email protected]f6cda752008-10-30 23:54:26921#if defined(COMPILER_GCC)
922// On Linux, with GCC, we can use __PRETTY_FUNCTION__ to get the demangled name
923// of the current function in the NOTIMPLEMENTED message.
924#define NOTIMPLEMENTED_MSG "Not implemented reached in " << __PRETTY_FUNCTION__
925#else
926#define NOTIMPLEMENTED_MSG "NOT IMPLEMENTED"
927#endif
928
[email protected]0dfc81b2008-08-25 03:44:40929#if NOTIMPLEMENTED_POLICY == 0
930#define NOTIMPLEMENTED() ;
931#elif NOTIMPLEMENTED_POLICY == 1
932// TODO, figure out how to generate a warning
933#define NOTIMPLEMENTED() COMPILE_ASSERT(false, NOT_IMPLEMENTED)
934#elif NOTIMPLEMENTED_POLICY == 2
935#define NOTIMPLEMENTED() COMPILE_ASSERT(false, NOT_IMPLEMENTED)
936#elif NOTIMPLEMENTED_POLICY == 3
937#define NOTIMPLEMENTED() NOTREACHED()
938#elif NOTIMPLEMENTED_POLICY == 4
[email protected]f6cda752008-10-30 23:54:26939#define NOTIMPLEMENTED() LOG(ERROR) << NOTIMPLEMENTED_MSG
[email protected]0dfc81b2008-08-25 03:44:40940#elif NOTIMPLEMENTED_POLICY == 5
941#define NOTIMPLEMENTED() do {\
942 static int count = 0;\
[email protected]f6cda752008-10-30 23:54:26943 LOG_IF(ERROR, 0 == count++) << NOTIMPLEMENTED_MSG;\
[email protected]0dfc81b2008-08-25 03:44:40944} while(0)
945#endif
946
[email protected]39be4242008-08-07 18:31:40947#endif // BASE_LOGGING_H_