blob: 19b22323c4048691fabd86480e3163051c8c9708 [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// Sets the log filter prefix. Any log message below LOG_ERROR severity that
224// doesn't start with this prefix with be silently ignored. The filter defaults
225// to NULL (everything is logged) if this function is not called. Messages
226// with severity of LOG_ERROR or higher will not be filtered.
227void SetLogFilterPrefix(const char* filter);
228
229// Sets the common items you want to be prepended to each log message.
230// process and thread IDs default to off, the timestamp defaults to on.
231// If this function is not called, logging defaults to writing the timestamp
232// only.
233void SetLogItems(bool enable_process_id, bool enable_thread_id,
234 bool enable_timestamp, bool enable_tickcount);
235
[email protected]81e0a852010-08-17 00:38:12236// Sets whether or not you'd like to see fatal debug messages popped up in
237// a dialog box or not.
238// Dialogs are not shown by default.
239void SetShowErrorDialogs(bool enable_dialogs);
240
initial.commitd7cae122008-07-26 21:49:38241// Sets the Log Assert Handler that will be used to notify of check failures.
[email protected]fb62a532009-02-12 01:19:05242// The default handler shows a dialog box and then terminate the process,
243// however clients can use this function to override with their own handling
244// (e.g. a silent one for Unit Tests)
initial.commitd7cae122008-07-26 21:49:38245typedef void (*LogAssertHandlerFunction)(const std::string& str);
246void SetLogAssertHandler(LogAssertHandlerFunction handler);
[email protected]fb62a532009-02-12 01:19:05247// Sets the Log Report Handler that will be used to notify of check failures
248// in non-debug mode. The default handler shows a dialog box and continues
249// the execution, however clients can use this function to override with their
250// own handling.
251typedef void (*LogReportHandlerFunction)(const std::string& str);
252void SetLogReportHandler(LogReportHandlerFunction handler);
initial.commitd7cae122008-07-26 21:49:38253
[email protected]2b07b8412009-11-25 15:26:34254// Sets the Log Message Handler that gets passed every log message before
255// it's sent to other log destinations (if any).
256// Returns true to signal that it handled the message and the message
257// should not be sent to other log destinations.
258typedef bool (*LogMessageHandlerFunction)(int severity, const std::string& str);
259void SetLogMessageHandler(LogMessageHandlerFunction handler);
260
initial.commitd7cae122008-07-26 21:49:38261typedef int LogSeverity;
262const LogSeverity LOG_INFO = 0;
263const LogSeverity LOG_WARNING = 1;
264const LogSeverity LOG_ERROR = 2;
[email protected]fb62a532009-02-12 01:19:05265const LogSeverity LOG_ERROR_REPORT = 3;
266const LogSeverity LOG_FATAL = 4;
267const LogSeverity LOG_NUM_SEVERITIES = 5;
initial.commitd7cae122008-07-26 21:49:38268
[email protected]081bd4c2010-06-24 01:01:04269// LOG_DFATAL_LEVEL is LOG_FATAL in debug mode, ERROR in normal mode
initial.commitd7cae122008-07-26 21:49:38270#ifdef NDEBUG
[email protected]081bd4c2010-06-24 01:01:04271const LogSeverity LOG_DFATAL_LEVEL = LOG_ERROR;
initial.commitd7cae122008-07-26 21:49:38272#else
273const LogSeverity LOG_DFATAL_LEVEL = LOG_FATAL;
274#endif
275
276// A few definitions of macros that don't generate much code. These are used
277// by LOG() and LOG_IF, etc. Since these are used all over our code, it's
278// better to have compact code for these operations.
[email protected]d8617a62009-10-09 23:52:20279#define COMPACT_GOOGLE_LOG_EX_INFO(ClassName, ...) \
280 logging::ClassName(__FILE__, __LINE__, logging::LOG_INFO , ##__VA_ARGS__)
281#define COMPACT_GOOGLE_LOG_EX_WARNING(ClassName, ...) \
282 logging::ClassName(__FILE__, __LINE__, logging::LOG_WARNING , ##__VA_ARGS__)
283#define COMPACT_GOOGLE_LOG_EX_ERROR(ClassName, ...) \
284 logging::ClassName(__FILE__, __LINE__, logging::LOG_ERROR , ##__VA_ARGS__)
285#define COMPACT_GOOGLE_LOG_EX_ERROR_REPORT(ClassName, ...) \
286 logging::ClassName(__FILE__, __LINE__, \
287 logging::LOG_ERROR_REPORT , ##__VA_ARGS__)
288#define COMPACT_GOOGLE_LOG_EX_FATAL(ClassName, ...) \
289 logging::ClassName(__FILE__, __LINE__, logging::LOG_FATAL , ##__VA_ARGS__)
290#define COMPACT_GOOGLE_LOG_EX_DFATAL(ClassName, ...) \
291 logging::ClassName(__FILE__, __LINE__, \
292 logging::LOG_DFATAL_LEVEL , ##__VA_ARGS__)
293
initial.commitd7cae122008-07-26 21:49:38294#define COMPACT_GOOGLE_LOG_INFO \
[email protected]d8617a62009-10-09 23:52:20295 COMPACT_GOOGLE_LOG_EX_INFO(LogMessage)
initial.commitd7cae122008-07-26 21:49:38296#define COMPACT_GOOGLE_LOG_WARNING \
[email protected]d8617a62009-10-09 23:52:20297 COMPACT_GOOGLE_LOG_EX_WARNING(LogMessage)
initial.commitd7cae122008-07-26 21:49:38298#define COMPACT_GOOGLE_LOG_ERROR \
[email protected]d8617a62009-10-09 23:52:20299 COMPACT_GOOGLE_LOG_EX_ERROR(LogMessage)
[email protected]fb62a532009-02-12 01:19:05300#define COMPACT_GOOGLE_LOG_ERROR_REPORT \
[email protected]d8617a62009-10-09 23:52:20301 COMPACT_GOOGLE_LOG_EX_ERROR_REPORT(LogMessage)
initial.commitd7cae122008-07-26 21:49:38302#define COMPACT_GOOGLE_LOG_FATAL \
[email protected]d8617a62009-10-09 23:52:20303 COMPACT_GOOGLE_LOG_EX_FATAL(LogMessage)
initial.commitd7cae122008-07-26 21:49:38304#define COMPACT_GOOGLE_LOG_DFATAL \
[email protected]d8617a62009-10-09 23:52:20305 COMPACT_GOOGLE_LOG_EX_DFATAL(LogMessage)
initial.commitd7cae122008-07-26 21:49:38306
307// wingdi.h defines ERROR to be 0. When we call LOG(ERROR), it gets
308// substituted with 0, and it expands to COMPACT_GOOGLE_LOG_0. To allow us
309// to keep using this syntax, we define this macro to do the same thing
310// as COMPACT_GOOGLE_LOG_ERROR, and also define ERROR the same way that
311// the Windows SDK does for consistency.
312#define ERROR 0
[email protected]d8617a62009-10-09 23:52:20313#define COMPACT_GOOGLE_LOG_EX_0(ClassName, ...) \
314 COMPACT_GOOGLE_LOG_EX_ERROR(ClassName , ##__VA_ARGS__)
315#define COMPACT_GOOGLE_LOG_0 COMPACT_GOOGLE_LOG_ERROR
initial.commitd7cae122008-07-26 21:49:38316
317// We use the preprocessor's merging operator, "##", so that, e.g.,
318// LOG(INFO) becomes the token COMPACT_GOOGLE_LOG_INFO. There's some funny
319// subtle difference between ostream member streaming functions (e.g.,
320// ostream::operator<<(int) and ostream non-member streaming functions
321// (e.g., ::operator<<(ostream&, string&): it turns out that it's
322// impossible to stream something like a string directly to an unnamed
323// ostream. We employ a neat hack by calling the stream() member
324// function of LogMessage which seems to avoid the problem.
[email protected]99b7c57f2010-09-29 19:26:36325//
326// We can't do any caching tricks with VLOG_IS_ON() like the
327// google-glog version since it requires GCC extensions. This means
328// that using the v-logging functions in conjunction with --vmodule
329// may be slow.
330#define VLOG_IS_ON(verboselevel) \
331 (logging::GetVlogLevel(__FILE__) >= (verboselevel))
initial.commitd7cae122008-07-26 21:49:38332
333#define LOG(severity) COMPACT_GOOGLE_LOG_ ## severity.stream()
334#define SYSLOG(severity) LOG(severity)
[email protected]99b7c57f2010-09-29 19:26:36335#define VLOG(verboselevel) LOG_IF(INFO, VLOG_IS_ON(verboselevel))
336
337// TODO(akalin): Add more VLOG variants, e.g. VPLOG.
initial.commitd7cae122008-07-26 21:49:38338
339#define LOG_IF(severity, condition) \
340 !(condition) ? (void) 0 : logging::LogMessageVoidify() & LOG(severity)
341#define SYSLOG_IF(severity, condition) LOG_IF(severity, condition)
[email protected]99b7c57f2010-09-29 19:26:36342#define VLOG_IF(verboselevel, condition) \
343 LOG_IF(INFO, (condition) && VLOG_IS_ON(verboselevel))
initial.commitd7cae122008-07-26 21:49:38344
345#define LOG_ASSERT(condition) \
346 LOG_IF(FATAL, !(condition)) << "Assert failed: " #condition ". "
347#define SYSLOG_ASSERT(condition) \
348 SYSLOG_IF(FATAL, !(condition)) << "Assert failed: " #condition ". "
349
[email protected]d8617a62009-10-09 23:52:20350#if defined(OS_WIN)
351#define LOG_GETLASTERROR(severity) \
352 COMPACT_GOOGLE_LOG_EX_ ## severity(Win32ErrorLogMessage, \
353 ::logging::GetLastSystemErrorCode()).stream()
354#define LOG_GETLASTERROR_MODULE(severity, module) \
355 COMPACT_GOOGLE_LOG_EX_ ## severity(Win32ErrorLogMessage, \
356 ::logging::GetLastSystemErrorCode(), module).stream()
357// PLOG is the usual error logging macro for each platform.
358#define PLOG(severity) LOG_GETLASTERROR(severity)
359#define DPLOG(severity) DLOG_GETLASTERROR(severity)
360#elif defined(OS_POSIX)
361#define LOG_ERRNO(severity) \
362 COMPACT_GOOGLE_LOG_EX_ ## severity(ErrnoLogMessage, \
363 ::logging::GetLastSystemErrorCode()).stream()
364// PLOG is the usual error logging macro for each platform.
365#define PLOG(severity) LOG_ERRNO(severity)
366#define DPLOG(severity) DLOG_ERRNO(severity)
367// TODO(tschmelcher): Should we add OSStatus logging for Mac?
368#endif
369
370#define PLOG_IF(severity, condition) \
371 !(condition) ? (void) 0 : logging::LogMessageVoidify() & PLOG(severity)
372
initial.commitd7cae122008-07-26 21:49:38373// CHECK dies with a fatal error if condition is not true. It is *not*
374// controlled by NDEBUG, so the check will be executed regardless of
375// compilation mode.
376#define CHECK(condition) \
377 LOG_IF(FATAL, !(condition)) << "Check failed: " #condition ". "
378
[email protected]d8617a62009-10-09 23:52:20379#define PCHECK(condition) \
380 PLOG_IF(FATAL, !(condition)) << "Check failed: " #condition ". "
381
initial.commitd7cae122008-07-26 21:49:38382// A container for a string pointer which can be evaluated to a bool -
383// true iff the pointer is NULL.
384struct CheckOpString {
385 CheckOpString(std::string* str) : str_(str) { }
386 // No destructor: if str_ is non-NULL, we're about to LOG(FATAL),
387 // so there's no point in cleaning up str_.
388 operator bool() const { return str_ != NULL; }
389 std::string* str_;
390};
391
392// Build the error message string. This is separate from the "Impl"
393// function template because it is not performance critical and so can
394// be out of line, while the "Impl" code should be inline.
395template<class t1, class t2>
396std::string* MakeCheckOpString(const t1& v1, const t2& v2, const char* names) {
397 std::ostringstream ss;
398 ss << names << " (" << v1 << " vs. " << v2 << ")";
399 std::string* msg = new std::string(ss.str());
400 return msg;
401}
402
403extern std::string* MakeCheckOpStringIntInt(int v1, int v2, const char* names);
404
405template<int, int>
[email protected]d3216442009-03-05 21:07:27406std::string* MakeCheckOpString(const int& v1,
407 const int& v2,
408 const char* names) {
initial.commitd7cae122008-07-26 21:49:38409 return MakeCheckOpStringIntInt(v1, v2, names);
410}
411
[email protected]e150c0382010-03-02 00:41:12412// Helper macro for binary operators.
413// Don't use this macro directly in your code, use CHECK_EQ et al below.
414#define CHECK_OP(name, op, val1, val2) \
415 if (logging::CheckOpString _result = \
416 logging::Check##name##Impl((val1), (val2), #val1 " " #op " " #val2)) \
417 logging::LogMessage(__FILE__, __LINE__, _result).stream()
418
419// Helper functions for string comparisons.
420// To avoid bloat, the definitions are in logging.cc.
421#define DECLARE_CHECK_STROP_IMPL(func, expected) \
422 std::string* Check##func##expected##Impl(const char* s1, \
423 const char* s2, \
424 const char* names);
425DECLARE_CHECK_STROP_IMPL(strcmp, true)
426DECLARE_CHECK_STROP_IMPL(strcmp, false)
427DECLARE_CHECK_STROP_IMPL(_stricmp, true)
428DECLARE_CHECK_STROP_IMPL(_stricmp, false)
429#undef DECLARE_CHECK_STROP_IMPL
430
431// Helper macro for string comparisons.
432// Don't use this macro directly in your code, use CHECK_STREQ et al below.
433#define CHECK_STROP(func, op, expected, s1, s2) \
434 while (CheckOpString _result = \
435 logging::Check##func##expected##Impl((s1), (s2), \
436 #s1 " " #op " " #s2)) \
437 LOG(FATAL) << *_result.str_
438
439// String (char*) equality/inequality checks.
440// CASE versions are case-insensitive.
441//
442// Note that "s1" and "s2" may be temporary strings which are destroyed
443// by the compiler at the end of the current "full expression"
444// (e.g. CHECK_STREQ(Foo().c_str(), Bar().c_str())).
445
446#define CHECK_STREQ(s1, s2) CHECK_STROP(strcmp, ==, true, s1, s2)
447#define CHECK_STRNE(s1, s2) CHECK_STROP(strcmp, !=, false, s1, s2)
448#define CHECK_STRCASEEQ(s1, s2) CHECK_STROP(_stricmp, ==, true, s1, s2)
449#define CHECK_STRCASENE(s1, s2) CHECK_STROP(_stricmp, !=, false, s1, s2)
450
451#define CHECK_INDEX(I,A) CHECK(I < (sizeof(A)/sizeof(A[0])))
452#define CHECK_BOUND(B,A) CHECK(B <= (sizeof(A)/sizeof(A[0])))
453
454#define CHECK_EQ(val1, val2) CHECK_OP(EQ, ==, val1, val2)
455#define CHECK_NE(val1, val2) CHECK_OP(NE, !=, val1, val2)
456#define CHECK_LE(val1, val2) CHECK_OP(LE, <=, val1, val2)
457#define CHECK_LT(val1, val2) CHECK_OP(LT, < , val1, val2)
458#define CHECK_GE(val1, val2) CHECK_OP(GE, >=, val1, val2)
459#define CHECK_GT(val1, val2) CHECK_OP(GT, > , val1, val2)
460
initial.commitd7cae122008-07-26 21:49:38461// Plus some debug-logging macros that get compiled to nothing for production
462//
463// DEBUG_MODE is for uses like
464// if (DEBUG_MODE) foo.CheckThatFoo();
465// instead of
466// #ifndef NDEBUG
467// foo.CheckThatFoo();
468// #endif
469
[email protected]e3cca332009-08-20 01:20:29470// http://crbug.com/16512 is open for a real fix for this. For now, Windows
471// uses OFFICIAL_BUILD and other platforms use the branding flag when NDEBUG is
472// defined.
473#if ( defined(OS_WIN) && defined(OFFICIAL_BUILD)) || \
474 (!defined(OS_WIN) && defined(NDEBUG) && defined(GOOGLE_CHROME_BUILD))
475// In order to have optimized code for official builds, remove DLOGs and
476// DCHECKs.
477#define OMIT_DLOG_AND_DCHECK 1
478#endif
479
480#ifdef OMIT_DLOG_AND_DCHECK
[email protected]94558e632008-12-11 22:10:17481
482#define DLOG(severity) \
483 true ? (void) 0 : logging::LogMessageVoidify() & LOG(severity)
484
485#define DLOG_IF(severity, condition) \
486 true ? (void) 0 : logging::LogMessageVoidify() & LOG(severity)
487
488#define DLOG_ASSERT(condition) \
489 true ? (void) 0 : LOG_ASSERT(condition)
490
[email protected]d8617a62009-10-09 23:52:20491#if defined(OS_WIN)
492#define DLOG_GETLASTERROR(severity) \
493 true ? (void) 0 : logging::LogMessageVoidify() & LOG_GETLASTERROR(severity)
494#define DLOG_GETLASTERROR_MODULE(severity, module) \
495 true ? (void) 0 : logging::LogMessageVoidify() & \
496 LOG_GETLASTERROR_MODULE(severity, module)
497#elif defined(OS_POSIX)
498#define DLOG_ERRNO(severity) \
499 true ? (void) 0 : logging::LogMessageVoidify() & LOG_ERRNO(severity)
500#endif
501
502#define DPLOG_IF(severity, condition) \
503 true ? (void) 0 : logging::LogMessageVoidify() & PLOG(severity)
504
[email protected]94558e632008-12-11 22:10:17505enum { DEBUG_MODE = 0 };
506
507// This macro can be followed by a sequence of stream parameters in
508// non-debug mode. The DCHECK and friends macros use this so that
509// the expanded expression DCHECK(foo) << "asdf" is still syntactically
510// valid, even though the expression will get optimized away.
[email protected]8c1766b92009-01-26 16:34:49511// In order to avoid variable unused warnings for code that only uses a
512// variable in a CHECK, we make sure to use the macro arguments.
[email protected]94558e632008-12-11 22:10:17513#define NDEBUG_EAT_STREAM_PARAMETERS \
514 logging::LogMessage(__FILE__, __LINE__).stream()
515
516#define DCHECK(condition) \
[email protected]8c1766b92009-01-26 16:34:49517 while (false && (condition)) NDEBUG_EAT_STREAM_PARAMETERS
[email protected]94558e632008-12-11 22:10:17518
[email protected]d8617a62009-10-09 23:52:20519#define DPCHECK(condition) \
520 while (false && (condition)) NDEBUG_EAT_STREAM_PARAMETERS
521
[email protected]94558e632008-12-11 22:10:17522#define DCHECK_EQ(val1, val2) \
[email protected]8c1766b92009-01-26 16:34:49523 while (false && (val1) == (val2)) NDEBUG_EAT_STREAM_PARAMETERS
[email protected]94558e632008-12-11 22:10:17524
525#define DCHECK_NE(val1, val2) \
[email protected]8c1766b92009-01-26 16:34:49526 while (false && (val1) == (val2)) NDEBUG_EAT_STREAM_PARAMETERS
[email protected]94558e632008-12-11 22:10:17527
528#define DCHECK_LE(val1, val2) \
[email protected]8c1766b92009-01-26 16:34:49529 while (false && (val1) == (val2)) NDEBUG_EAT_STREAM_PARAMETERS
[email protected]94558e632008-12-11 22:10:17530
531#define DCHECK_LT(val1, val2) \
[email protected]8c1766b92009-01-26 16:34:49532 while (false && (val1) == (val2)) NDEBUG_EAT_STREAM_PARAMETERS
[email protected]94558e632008-12-11 22:10:17533
534#define DCHECK_GE(val1, val2) \
[email protected]8c1766b92009-01-26 16:34:49535 while (false && (val1) == (val2)) NDEBUG_EAT_STREAM_PARAMETERS
[email protected]94558e632008-12-11 22:10:17536
537#define DCHECK_GT(val1, val2) \
[email protected]8c1766b92009-01-26 16:34:49538 while (false && (val1) == (val2)) NDEBUG_EAT_STREAM_PARAMETERS
[email protected]94558e632008-12-11 22:10:17539
540#define DCHECK_STREQ(str1, str2) \
[email protected]8c1766b92009-01-26 16:34:49541 while (false && (str1) == (str2)) NDEBUG_EAT_STREAM_PARAMETERS
[email protected]94558e632008-12-11 22:10:17542
543#define DCHECK_STRCASEEQ(str1, str2) \
[email protected]8c1766b92009-01-26 16:34:49544 while (false && (str1) == (str2)) NDEBUG_EAT_STREAM_PARAMETERS
[email protected]94558e632008-12-11 22:10:17545
546#define DCHECK_STRNE(str1, str2) \
[email protected]8c1766b92009-01-26 16:34:49547 while (false && (str1) == (str2)) NDEBUG_EAT_STREAM_PARAMETERS
[email protected]94558e632008-12-11 22:10:17548
549#define DCHECK_STRCASENE(str1, str2) \
[email protected]8c1766b92009-01-26 16:34:49550 while (false && (str1) == (str2)) NDEBUG_EAT_STREAM_PARAMETERS
[email protected]94558e632008-12-11 22:10:17551
[email protected]e3cca332009-08-20 01:20:29552#else // OMIT_DLOG_AND_DCHECK
553
initial.commitd7cae122008-07-26 21:49:38554#ifndef NDEBUG
[email protected]94558e632008-12-11 22:10:17555// On a regular debug build, we want to have DCHECKS and DLOGS enabled.
initial.commitd7cae122008-07-26 21:49:38556
557#define DLOG(severity) LOG(severity)
558#define DLOG_IF(severity, condition) LOG_IF(severity, condition)
559#define DLOG_ASSERT(condition) LOG_ASSERT(condition)
560
[email protected]d8617a62009-10-09 23:52:20561#if defined(OS_WIN)
562#define DLOG_GETLASTERROR(severity) LOG_GETLASTERROR(severity)
563#define DLOG_GETLASTERROR_MODULE(severity, module) \
564 LOG_GETLASTERROR_MODULE(severity, module)
565#elif defined(OS_POSIX)
566#define DLOG_ERRNO(severity) LOG_ERRNO(severity)
567#endif
568
569#define DPLOG_IF(severity, condition) PLOG_IF(severity, condition)
570
initial.commitd7cae122008-07-26 21:49:38571// debug-only checking. not executed in NDEBUG mode.
572enum { DEBUG_MODE = 1 };
[email protected]e150c0382010-03-02 00:41:12573#define DCHECK(condition) CHECK(condition)
574#define DPCHECK(condition) PCHECK(condition)
[email protected]d8617a62009-10-09 23:52:20575
initial.commitd7cae122008-07-26 21:49:38576// Helper macro for binary operators.
577// Don't use this macro directly in your code, use DCHECK_EQ et al below.
578#define DCHECK_OP(name, op, val1, val2) \
579 if (logging::CheckOpString _result = \
580 logging::Check##name##Impl((val1), (val2), #val1 " " #op " " #val2)) \
581 logging::LogMessage(__FILE__, __LINE__, _result).stream()
582
initial.commitd7cae122008-07-26 21:49:38583// Helper macro for string comparisons.
584// Don't use this macro directly in your code, use CHECK_STREQ et al below.
585#define DCHECK_STROP(func, op, expected, s1, s2) \
586 while (CheckOpString _result = \
587 logging::Check##func##expected##Impl((s1), (s2), \
588 #s1 " " #op " " #s2)) \
589 LOG(FATAL) << *_result.str_
590
591// String (char*) equality/inequality checks.
592// CASE versions are case-insensitive.
593//
594// Note that "s1" and "s2" may be temporary strings which are destroyed
595// by the compiler at the end of the current "full expression"
596// (e.g. DCHECK_STREQ(Foo().c_str(), Bar().c_str())).
597
598#define DCHECK_STREQ(s1, s2) DCHECK_STROP(strcmp, ==, true, s1, s2)
599#define DCHECK_STRNE(s1, s2) DCHECK_STROP(strcmp, !=, false, s1, s2)
600#define DCHECK_STRCASEEQ(s1, s2) DCHECK_STROP(_stricmp, ==, true, s1, s2)
601#define DCHECK_STRCASENE(s1, s2) DCHECK_STROP(_stricmp, !=, false, s1, s2)
602
603#define DCHECK_INDEX(I,A) DCHECK(I < (sizeof(A)/sizeof(A[0])))
604#define DCHECK_BOUND(B,A) DCHECK(B <= (sizeof(A)/sizeof(A[0])))
605
606#else // NDEBUG
[email protected]94558e632008-12-11 22:10:17607// On a regular release build we want to be able to enable DCHECKS through the
608// command line.
initial.commitd7cae122008-07-26 21:49:38609#define DLOG(severity) \
610 true ? (void) 0 : logging::LogMessageVoidify() & LOG(severity)
611
612#define DLOG_IF(severity, condition) \
613 true ? (void) 0 : logging::LogMessageVoidify() & LOG(severity)
614
615#define DLOG_ASSERT(condition) \
616 true ? (void) 0 : LOG_ASSERT(condition)
617
[email protected]d8617a62009-10-09 23:52:20618#if defined(OS_WIN)
619#define DLOG_GETLASTERROR(severity) \
620 true ? (void) 0 : logging::LogMessageVoidify() & LOG_GETLASTERROR(severity)
621#define DLOG_GETLASTERROR_MODULE(severity, module) \
622 true ? (void) 0 : logging::LogMessageVoidify() & \
623 LOG_GETLASTERROR_MODULE(severity, module)
624#elif defined(OS_POSIX)
625#define DLOG_ERRNO(severity) \
626 true ? (void) 0 : logging::LogMessageVoidify() & LOG_ERRNO(severity)
627#endif
628
629#define DPLOG_IF(severity, condition) \
630 true ? (void) 0 : logging::LogMessageVoidify() & PLOG(severity)
631
initial.commitd7cae122008-07-26 21:49:38632enum { DEBUG_MODE = 0 };
633
634// This macro can be followed by a sequence of stream parameters in
635// non-debug mode. The DCHECK and friends macros use this so that
636// the expanded expression DCHECK(foo) << "asdf" is still syntactically
637// valid, even though the expression will get optimized away.
638#define NDEBUG_EAT_STREAM_PARAMETERS \
639 logging::LogMessage(__FILE__, __LINE__).stream()
640
641// Set to true in InitLogging when we want to enable the dchecks in release.
642extern bool g_enable_dcheck;
643#define DCHECK(condition) \
644 !logging::g_enable_dcheck ? void (0) : \
[email protected]fb62a532009-02-12 01:19:05645 LOG_IF(ERROR_REPORT, !(condition)) << "Check failed: " #condition ". "
initial.commitd7cae122008-07-26 21:49:38646
[email protected]d8617a62009-10-09 23:52:20647#define DPCHECK(condition) \
648 !logging::g_enable_dcheck ? void (0) : \
649 PLOG_IF(ERROR_REPORT, !(condition)) << "Check failed: " #condition ". "
650
initial.commitd7cae122008-07-26 21:49:38651// Helper macro for binary operators.
652// Don't use this macro directly in your code, use DCHECK_EQ et al below.
653#define DCHECK_OP(name, op, val1, val2) \
654 if (logging::g_enable_dcheck) \
655 if (logging::CheckOpString _result = \
656 logging::Check##name##Impl((val1), (val2), #val1 " " #op " " #val2)) \
[email protected]fb62a532009-02-12 01:19:05657 logging::LogMessage(__FILE__, __LINE__, logging::LOG_ERROR_REPORT, \
658 _result).stream()
initial.commitd7cae122008-07-26 21:49:38659
660#define DCHECK_STREQ(str1, str2) \
661 while (false) NDEBUG_EAT_STREAM_PARAMETERS
662
663#define DCHECK_STRCASEEQ(str1, str2) \
664 while (false) NDEBUG_EAT_STREAM_PARAMETERS
665
666#define DCHECK_STRNE(str1, str2) \
667 while (false) NDEBUG_EAT_STREAM_PARAMETERS
668
669#define DCHECK_STRCASENE(str1, str2) \
670 while (false) NDEBUG_EAT_STREAM_PARAMETERS
671
672#endif // NDEBUG
673
initial.commitd7cae122008-07-26 21:49:38674// Equality/Inequality checks - compare two values, and log a LOG_FATAL message
675// including the two values when the result is not as expected. The values
676// must have operator<<(ostream, ...) defined.
677//
678// You may append to the error message like so:
679// DCHECK_NE(1, 2) << ": The world must be ending!";
680//
681// We are very careful to ensure that each argument is evaluated exactly
682// once, and that anything which is legal to pass as a function argument is
683// legal here. In particular, the arguments may be temporary expressions
684// which will end up being destroyed at the end of the apparent statement,
685// for example:
686// DCHECK_EQ(string("abc")[1], 'b');
687//
688// WARNING: These may not compile correctly if one of the arguments is a pointer
689// and the other is NULL. To work around this, simply static_cast NULL to the
690// type of the desired pointer.
691
692#define DCHECK_EQ(val1, val2) DCHECK_OP(EQ, ==, val1, val2)
693#define DCHECK_NE(val1, val2) DCHECK_OP(NE, !=, val1, val2)
694#define DCHECK_LE(val1, val2) DCHECK_OP(LE, <=, val1, val2)
695#define DCHECK_LT(val1, val2) DCHECK_OP(LT, < , val1, val2)
696#define DCHECK_GE(val1, val2) DCHECK_OP(GE, >=, val1, val2)
697#define DCHECK_GT(val1, val2) DCHECK_OP(GT, > , val1, val2)
698
[email protected]e3cca332009-08-20 01:20:29699#endif // OMIT_DLOG_AND_DCHECK
700#undef OMIT_DLOG_AND_DCHECK
initial.commitd7cae122008-07-26 21:49:38701
[email protected]e150c0382010-03-02 00:41:12702
703// Helper functions for CHECK_OP macro.
704// The (int, int) specialization works around the issue that the compiler
705// will not instantiate the template version of the function on values of
706// unnamed enum type - see comment below.
707#define DEFINE_CHECK_OP_IMPL(name, op) \
708 template <class t1, class t2> \
709 inline std::string* Check##name##Impl(const t1& v1, const t2& v2, \
710 const char* names) { \
711 if (v1 op v2) return NULL; \
712 else return MakeCheckOpString(v1, v2, names); \
713 } \
714 inline std::string* Check##name##Impl(int v1, int v2, const char* names) { \
715 if (v1 op v2) return NULL; \
716 else return MakeCheckOpString(v1, v2, names); \
717 }
718DEFINE_CHECK_OP_IMPL(EQ, ==)
719DEFINE_CHECK_OP_IMPL(NE, !=)
720DEFINE_CHECK_OP_IMPL(LE, <=)
721DEFINE_CHECK_OP_IMPL(LT, < )
722DEFINE_CHECK_OP_IMPL(GE, >=)
723DEFINE_CHECK_OP_IMPL(GT, > )
724#undef DEFINE_CHECK_OP_IMPL
725
initial.commitd7cae122008-07-26 21:49:38726#define NOTREACHED() DCHECK(false)
727
728// Redefine the standard assert to use our nice log files
729#undef assert
730#define assert(x) DLOG_ASSERT(x)
731
732// This class more or less represents a particular log message. You
733// create an instance of LogMessage and then stream stuff to it.
734// When you finish streaming to it, ~LogMessage is called and the
735// full message gets streamed to the appropriate destination.
736//
737// You shouldn't actually use LogMessage's constructor to log things,
738// though. You should use the LOG() macro (and variants thereof)
739// above.
740class LogMessage {
741 public:
742 LogMessage(const char* file, int line, LogSeverity severity, int ctr);
743
744 // Two special constructors that generate reduced amounts of code at
745 // LOG call sites for common cases.
746 //
747 // Used for LOG(INFO): Implied are:
748 // severity = LOG_INFO, ctr = 0
749 //
750 // Using this constructor instead of the more complex constructor above
751 // saves a couple of bytes per call site.
752 LogMessage(const char* file, int line);
753
754 // Used for LOG(severity) where severity != INFO. Implied
755 // are: ctr = 0
756 //
757 // Using this constructor instead of the more complex constructor above
758 // saves a couple of bytes per call site.
759 LogMessage(const char* file, int line, LogSeverity severity);
760
761 // A special constructor used for check failures.
762 // Implied severity = LOG_FATAL
763 LogMessage(const char* file, int line, const CheckOpString& result);
764
[email protected]fb62a532009-02-12 01:19:05765 // A special constructor used for check failures, with the option to
766 // specify severity.
767 LogMessage(const char* file, int line, LogSeverity severity,
768 const CheckOpString& result);
769
initial.commitd7cae122008-07-26 21:49:38770 ~LogMessage();
771
772 std::ostream& stream() { return stream_; }
773
774 private:
775 void Init(const char* file, int line);
776
777 LogSeverity severity_;
778 std::ostringstream stream_;
[email protected]c88873922008-07-30 13:02:03779 size_t message_start_; // Offset of the start of the message (past prefix
780 // info).
[email protected]3f85caa2009-04-14 16:52:11781#if defined(OS_WIN)
782 // Stores the current value of GetLastError in the constructor and restores
783 // it in the destructor by calling SetLastError.
784 // This is useful since the LogMessage class uses a lot of Win32 calls
785 // that will lose the value of GLE and the code that called the log function
786 // will have lost the thread error value when the log call returns.
787 class SaveLastError {
788 public:
789 SaveLastError();
790 ~SaveLastError();
791
792 unsigned long get_error() const { return last_error_; }
793
794 protected:
795 unsigned long last_error_;
796 };
797
798 SaveLastError last_error_;
799#endif
initial.commitd7cae122008-07-26 21:49:38800
[email protected]39be4242008-08-07 18:31:40801 DISALLOW_COPY_AND_ASSIGN(LogMessage);
initial.commitd7cae122008-07-26 21:49:38802};
803
804// A non-macro interface to the log facility; (useful
805// when the logging level is not a compile-time constant).
806inline void LogAtLevel(int const log_level, std::string const &msg) {
807 LogMessage(__FILE__, __LINE__, log_level).stream() << msg;
808}
809
810// This class is used to explicitly ignore values in the conditional
811// logging macros. This avoids compiler warnings like "value computed
812// is not used" and "statement has no effect".
813class LogMessageVoidify {
814 public:
815 LogMessageVoidify() { }
816 // This has to be an operator with a precedence lower than << but
817 // higher than ?:
818 void operator&(std::ostream&) { }
819};
820
[email protected]d8617a62009-10-09 23:52:20821#if defined(OS_WIN)
822typedef unsigned long SystemErrorCode;
823#elif defined(OS_POSIX)
824typedef int SystemErrorCode;
825#endif
826
827// Alias for ::GetLastError() on Windows and errno on POSIX. Avoids having to
828// pull in windows.h just for GetLastError() and DWORD.
829SystemErrorCode GetLastSystemErrorCode();
830
831#if defined(OS_WIN)
832// Appends a formatted system message of the GetLastError() type.
833class Win32ErrorLogMessage {
834 public:
835 Win32ErrorLogMessage(const char* file,
836 int line,
837 LogSeverity severity,
838 SystemErrorCode err,
839 const char* module);
840
841 Win32ErrorLogMessage(const char* file,
842 int line,
843 LogSeverity severity,
844 SystemErrorCode err);
845
846 std::ostream& stream() { return log_message_.stream(); }
847
848 // Appends the error message before destructing the encapsulated class.
849 ~Win32ErrorLogMessage();
850
851 private:
852 SystemErrorCode err_;
853 // Optional name of the module defining the error.
854 const char* module_;
855 LogMessage log_message_;
856
857 DISALLOW_COPY_AND_ASSIGN(Win32ErrorLogMessage);
858};
859#elif defined(OS_POSIX)
860// Appends a formatted system message of the errno type
861class ErrnoLogMessage {
862 public:
863 ErrnoLogMessage(const char* file,
864 int line,
865 LogSeverity severity,
866 SystemErrorCode err);
867
868 std::ostream& stream() { return log_message_.stream(); }
869
870 // Appends the error message before destructing the encapsulated class.
871 ~ErrnoLogMessage();
872
873 private:
874 SystemErrorCode err_;
875 LogMessage log_message_;
876
877 DISALLOW_COPY_AND_ASSIGN(ErrnoLogMessage);
878};
879#endif // OS_WIN
880
initial.commitd7cae122008-07-26 21:49:38881// Closes the log file explicitly if open.
882// NOTE: Since the log file is opened as necessary by the action of logging
883// statements, there's no guarantee that it will stay closed
884// after this call.
885void CloseLogFile();
886
[email protected]e36ddc82009-12-08 04:22:50887// Async signal safe logging mechanism.
888void RawLog(int level, const char* message);
889
890#define RAW_LOG(level, message) logging::RawLog(logging::LOG_ ## level, message)
891
892#define RAW_CHECK(condition) \
893 do { \
894 if (!(condition)) \
895 logging::RawLog(logging::LOG_FATAL, "Check failed: " #condition "\n"); \
896 } while (0)
897
[email protected]39be4242008-08-07 18:31:40898} // namespace logging
initial.commitd7cae122008-07-26 21:49:38899
[email protected]46ce5b562010-06-16 18:39:53900// These functions are provided as a convenience for logging, which is where we
901// use streams (it is against Google style to use streams in other places). It
902// is designed to allow you to emit non-ASCII Unicode strings to the log file,
903// which is normally ASCII. It is relatively slow, so try not to use it for
904// common cases. Non-ASCII characters will be converted to UTF-8 by these
905// operators.
906std::ostream& operator<<(std::ostream& out, const wchar_t* wstr);
907inline std::ostream& operator<<(std::ostream& out, const std::wstring& wstr) {
908 return out << wstr.c_str();
909}
910
[email protected]0dfc81b2008-08-25 03:44:40911// The NOTIMPLEMENTED() macro annotates codepaths which have
912// not been implemented yet.
913//
914// The implementation of this macro is controlled by NOTIMPLEMENTED_POLICY:
915// 0 -- Do nothing (stripped by compiler)
916// 1 -- Warn at compile time
917// 2 -- Fail at compile time
918// 3 -- Fail at runtime (DCHECK)
919// 4 -- [default] LOG(ERROR) at runtime
920// 5 -- LOG(ERROR) at runtime, only once per call-site
921
922#ifndef NOTIMPLEMENTED_POLICY
923// Select default policy: LOG(ERROR)
924#define NOTIMPLEMENTED_POLICY 4
925#endif
926
[email protected]f6cda752008-10-30 23:54:26927#if defined(COMPILER_GCC)
928// On Linux, with GCC, we can use __PRETTY_FUNCTION__ to get the demangled name
929// of the current function in the NOTIMPLEMENTED message.
930#define NOTIMPLEMENTED_MSG "Not implemented reached in " << __PRETTY_FUNCTION__
931#else
932#define NOTIMPLEMENTED_MSG "NOT IMPLEMENTED"
933#endif
934
[email protected]0dfc81b2008-08-25 03:44:40935#if NOTIMPLEMENTED_POLICY == 0
936#define NOTIMPLEMENTED() ;
937#elif NOTIMPLEMENTED_POLICY == 1
938// TODO, figure out how to generate a warning
939#define NOTIMPLEMENTED() COMPILE_ASSERT(false, NOT_IMPLEMENTED)
940#elif NOTIMPLEMENTED_POLICY == 2
941#define NOTIMPLEMENTED() COMPILE_ASSERT(false, NOT_IMPLEMENTED)
942#elif NOTIMPLEMENTED_POLICY == 3
943#define NOTIMPLEMENTED() NOTREACHED()
944#elif NOTIMPLEMENTED_POLICY == 4
[email protected]f6cda752008-10-30 23:54:26945#define NOTIMPLEMENTED() LOG(ERROR) << NOTIMPLEMENTED_MSG
[email protected]0dfc81b2008-08-25 03:44:40946#elif NOTIMPLEMENTED_POLICY == 5
947#define NOTIMPLEMENTED() do {\
948 static int count = 0;\
[email protected]f6cda752008-10-30 23:54:26949 LOG_IF(ERROR, 0 == count++) << NOTIMPLEMENTED_MSG;\
[email protected]0dfc81b2008-08-25 03:44:40950} while(0)
951#endif
952
[email protected]39be4242008-08-07 18:31:40953#endif // BASE_LOGGING_H_