OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_LOGGING_H_ | 5 #ifndef BASE_LOGGING_H_ |
6 #define BASE_LOGGING_H_ | 6 #define BASE_LOGGING_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <cstring> | 9 #include <cstring> |
10 #include <sstream> | 10 #include <sstream> |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 | 251 |
252 // Plus some debug-logging macros that get compiled to nothing for production | 252 // Plus some debug-logging macros that get compiled to nothing for production |
253 // | 253 // |
254 // DEBUG_MODE is for uses like | 254 // DEBUG_MODE is for uses like |
255 // if (DEBUG_MODE) foo.CheckThatFoo(); | 255 // if (DEBUG_MODE) foo.CheckThatFoo(); |
256 // instead of | 256 // instead of |
257 // #ifndef NDEBUG | 257 // #ifndef NDEBUG |
258 // foo.CheckThatFoo(); | 258 // foo.CheckThatFoo(); |
259 // #endif | 259 // #endif |
260 | 260 |
261 #ifdef OFFICIAL_BUILD | |
262 // We want to have optimized code for an official build so we remove DLOGS and | |
263 // DCHECK from the executable. | |
264 | |
265 #define DLOG(severity) \ | |
266 true ? (void) 0 : logging::LogMessageVoidify() & LOG(severity) | |
267 | |
268 #define DLOG_IF(severity, condition) \ | |
269 true ? (void) 0 : logging::LogMessageVoidify() & LOG(severity) | |
270 | |
271 #define DLOG_ASSERT(condition) \ | |
272 true ? (void) 0 : LOG_ASSERT(condition) | |
273 | |
274 enum { DEBUG_MODE = 0 }; | |
275 | |
276 // This macro can be followed by a sequence of stream parameters in | |
277 // non-debug mode. The DCHECK and friends macros use this so that | |
278 // the expanded expression DCHECK(foo) << "asdf" is still syntactically | |
279 // valid, even though the expression will get optimized away. | |
280 #define NDEBUG_EAT_STREAM_PARAMETERS \ | |
281 logging::LogMessage(__FILE__, __LINE__).stream() | |
282 | |
283 #define DCHECK(condition) \ | |
284 while (false) NDEBUG_EAT_STREAM_PARAMETERS | |
285 | |
286 #define DCHECK_EQ(val1, val2) \ | |
287 while (false) NDEBUG_EAT_STREAM_PARAMETERS | |
288 | |
289 #define DCHECK_NE(val1, val2) \ | |
290 while (false) NDEBUG_EAT_STREAM_PARAMETERS | |
291 | |
292 #define DCHECK_LE(val1, val2) \ | |
293 while (false) NDEBUG_EAT_STREAM_PARAMETERS | |
294 | |
295 #define DCHECK_LT(val1, val2) \ | |
296 while (false) NDEBUG_EAT_STREAM_PARAMETERS | |
297 | |
298 #define DCHECK_GE(val1, val2) \ | |
299 while (false) NDEBUG_EAT_STREAM_PARAMETERS | |
300 | |
301 #define DCHECK_GT(val1, val2) \ | |
302 while (false) NDEBUG_EAT_STREAM_PARAMETERS | |
303 | |
304 #define DCHECK_STREQ(str1, str2) \ | |
305 while (false) NDEBUG_EAT_STREAM_PARAMETERS | |
306 | |
307 #define DCHECK_STRCASEEQ(str1, str2) \ | |
308 while (false) NDEBUG_EAT_STREAM_PARAMETERS | |
309 | |
310 #define DCHECK_STRNE(str1, str2) \ | |
311 while (false) NDEBUG_EAT_STREAM_PARAMETERS | |
312 | |
313 #define DCHECK_STRCASENE(str1, str2) \ | |
314 while (false) NDEBUG_EAT_STREAM_PARAMETERS | |
315 | |
316 #else // OFFICIAL_BUILD | |
Nicolas Sylvain
2008/12/06 15:29:50
The comment here is confusing, maybe we should jus
| |
261 #ifndef NDEBUG | 317 #ifndef NDEBUG |
318 // On a regular debug build, we want to have DCHECKS and DLOGS enabled. | |
262 | 319 |
263 #define DLOG(severity) LOG(severity) | 320 #define DLOG(severity) LOG(severity) |
264 #define DLOG_IF(severity, condition) LOG_IF(severity, condition) | 321 #define DLOG_IF(severity, condition) LOG_IF(severity, condition) |
265 #define DLOG_ASSERT(condition) LOG_ASSERT(condition) | 322 #define DLOG_ASSERT(condition) LOG_ASSERT(condition) |
266 | 323 |
267 // debug-only checking. not executed in NDEBUG mode. | 324 // debug-only checking. not executed in NDEBUG mode. |
268 enum { DEBUG_MODE = 1 }; | 325 enum { DEBUG_MODE = 1 }; |
269 #define DCHECK(condition) \ | 326 #define DCHECK(condition) \ |
270 LOG_IF(FATAL, !(condition)) << "Check failed: " #condition ". " | 327 LOG_IF(FATAL, !(condition)) << "Check failed: " #condition ". " |
271 | 328 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
305 | 362 |
306 #define DCHECK_STREQ(s1, s2) DCHECK_STROP(strcmp, ==, true, s1, s2) | 363 #define DCHECK_STREQ(s1, s2) DCHECK_STROP(strcmp, ==, true, s1, s2) |
307 #define DCHECK_STRNE(s1, s2) DCHECK_STROP(strcmp, !=, false, s1, s2) | 364 #define DCHECK_STRNE(s1, s2) DCHECK_STROP(strcmp, !=, false, s1, s2) |
308 #define DCHECK_STRCASEEQ(s1, s2) DCHECK_STROP(_stricmp, ==, true, s1, s2) | 365 #define DCHECK_STRCASEEQ(s1, s2) DCHECK_STROP(_stricmp, ==, true, s1, s2) |
309 #define DCHECK_STRCASENE(s1, s2) DCHECK_STROP(_stricmp, !=, false, s1, s2) | 366 #define DCHECK_STRCASENE(s1, s2) DCHECK_STROP(_stricmp, !=, false, s1, s2) |
310 | 367 |
311 #define DCHECK_INDEX(I,A) DCHECK(I < (sizeof(A)/sizeof(A[0]))) | 368 #define DCHECK_INDEX(I,A) DCHECK(I < (sizeof(A)/sizeof(A[0]))) |
312 #define DCHECK_BOUND(B,A) DCHECK(B <= (sizeof(A)/sizeof(A[0]))) | 369 #define DCHECK_BOUND(B,A) DCHECK(B <= (sizeof(A)/sizeof(A[0]))) |
313 | 370 |
314 #else // NDEBUG | 371 #else // NDEBUG |
315 | 372 // On a regular release build we want to be able to enable DCHECKS through the |
373 // command line. | |
316 #define DLOG(severity) \ | 374 #define DLOG(severity) \ |
317 true ? (void) 0 : logging::LogMessageVoidify() & LOG(severity) | 375 true ? (void) 0 : logging::LogMessageVoidify() & LOG(severity) |
318 | 376 |
319 #define DLOG_IF(severity, condition) \ | 377 #define DLOG_IF(severity, condition) \ |
320 true ? (void) 0 : logging::LogMessageVoidify() & LOG(severity) | 378 true ? (void) 0 : logging::LogMessageVoidify() & LOG(severity) |
321 | 379 |
322 #define DLOG_ASSERT(condition) \ | 380 #define DLOG_ASSERT(condition) \ |
323 true ? (void) 0 : LOG_ASSERT(condition) | 381 true ? (void) 0 : LOG_ASSERT(condition) |
324 | 382 |
325 enum { DEBUG_MODE = 0 }; | 383 enum { DEBUG_MODE = 0 }; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 // and the other is NULL. To work around this, simply static_cast NULL to the | 458 // and the other is NULL. To work around this, simply static_cast NULL to the |
401 // type of the desired pointer. | 459 // type of the desired pointer. |
402 | 460 |
403 #define DCHECK_EQ(val1, val2) DCHECK_OP(EQ, ==, val1, val2) | 461 #define DCHECK_EQ(val1, val2) DCHECK_OP(EQ, ==, val1, val2) |
404 #define DCHECK_NE(val1, val2) DCHECK_OP(NE, !=, val1, val2) | 462 #define DCHECK_NE(val1, val2) DCHECK_OP(NE, !=, val1, val2) |
405 #define DCHECK_LE(val1, val2) DCHECK_OP(LE, <=, val1, val2) | 463 #define DCHECK_LE(val1, val2) DCHECK_OP(LE, <=, val1, val2) |
406 #define DCHECK_LT(val1, val2) DCHECK_OP(LT, < , val1, val2) | 464 #define DCHECK_LT(val1, val2) DCHECK_OP(LT, < , val1, val2) |
407 #define DCHECK_GE(val1, val2) DCHECK_OP(GE, >=, val1, val2) | 465 #define DCHECK_GE(val1, val2) DCHECK_OP(GE, >=, val1, val2) |
408 #define DCHECK_GT(val1, val2) DCHECK_OP(GT, > , val1, val2) | 466 #define DCHECK_GT(val1, val2) DCHECK_OP(GT, > , val1, val2) |
409 | 467 |
468 #endif // OFFICIAL_BUILD | |
410 | 469 |
411 #define NOTREACHED() DCHECK(false) | 470 #define NOTREACHED() DCHECK(false) |
412 | 471 |
413 // Redefine the standard assert to use our nice log files | 472 // Redefine the standard assert to use our nice log files |
414 #undef assert | 473 #undef assert |
415 #define assert(x) DLOG_ASSERT(x) | 474 #define assert(x) DLOG_ASSERT(x) |
416 | 475 |
417 // This class more or less represents a particular log message. You | 476 // This class more or less represents a particular log message. You |
418 // create an instance of LogMessage and then stream stuff to it. | 477 // create an instance of LogMessage and then stream stuff to it. |
419 // When you finish streaming to it, ~LogMessage is called and the | 478 // When you finish streaming to it, ~LogMessage is called and the |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
534 #elif NOTIMPLEMENTED_POLICY == 4 | 593 #elif NOTIMPLEMENTED_POLICY == 4 |
535 #define NOTIMPLEMENTED() LOG(ERROR) << NOTIMPLEMENTED_MSG | 594 #define NOTIMPLEMENTED() LOG(ERROR) << NOTIMPLEMENTED_MSG |
536 #elif NOTIMPLEMENTED_POLICY == 5 | 595 #elif NOTIMPLEMENTED_POLICY == 5 |
537 #define NOTIMPLEMENTED() do {\ | 596 #define NOTIMPLEMENTED() do {\ |
538 static int count = 0;\ | 597 static int count = 0;\ |
539 LOG_IF(ERROR, 0 == count++) << NOTIMPLEMENTED_MSG;\ | 598 LOG_IF(ERROR, 0 == count++) << NOTIMPLEMENTED_MSG;\ |
540 } while(0) | 599 } while(0) |
541 #endif | 600 #endif |
542 | 601 |
543 #endif // BASE_LOGGING_H_ | 602 #endif // BASE_LOGGING_H_ |
544 | |
OLD | NEW |