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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 273 |
274 // Plus some debug-logging macros that get compiled to nothing for production | 274 // Plus some debug-logging macros that get compiled to nothing for production |
275 // | 275 // |
276 // DEBUG_MODE is for uses like | 276 // DEBUG_MODE is for uses like |
277 // if (DEBUG_MODE) foo.CheckThatFoo(); | 277 // if (DEBUG_MODE) foo.CheckThatFoo(); |
278 // instead of | 278 // instead of |
279 // #ifndef NDEBUG | 279 // #ifndef NDEBUG |
280 // foo.CheckThatFoo(); | 280 // foo.CheckThatFoo(); |
281 // #endif | 281 // #endif |
282 | 282 |
283 #ifdef OFFICIAL_BUILD | 283 // http://crbug.com/16512 is open for a real fix for this. For now, Windows |
284 // We want to have optimized code for an official build so we remove DLOGS and | 284 // uses OFFICIAL_BUILD and other platforms use the branding flag when NDEBUG is |
285 // DCHECK from the executable. | 285 // defined. |
| 286 #if ( defined(OS_WIN) && defined(OFFICIAL_BUILD)) || \ |
| 287 (!defined(OS_WIN) && defined(NDEBUG) && defined(GOOGLE_CHROME_BUILD)) |
| 288 // In order to have optimized code for official builds, remove DLOGs and |
| 289 // DCHECKs. |
| 290 #define OMIT_DLOG_AND_DCHECK 1 |
| 291 #endif |
| 292 |
| 293 #ifdef OMIT_DLOG_AND_DCHECK |
286 | 294 |
287 #define DLOG(severity) \ | 295 #define DLOG(severity) \ |
288 true ? (void) 0 : logging::LogMessageVoidify() & LOG(severity) | 296 true ? (void) 0 : logging::LogMessageVoidify() & LOG(severity) |
289 | 297 |
290 #define DLOG_IF(severity, condition) \ | 298 #define DLOG_IF(severity, condition) \ |
291 true ? (void) 0 : logging::LogMessageVoidify() & LOG(severity) | 299 true ? (void) 0 : logging::LogMessageVoidify() & LOG(severity) |
292 | 300 |
293 #define DLOG_ASSERT(condition) \ | 301 #define DLOG_ASSERT(condition) \ |
294 true ? (void) 0 : LOG_ASSERT(condition) | 302 true ? (void) 0 : LOG_ASSERT(condition) |
295 | 303 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 | 338 |
331 #define DCHECK_STRCASEEQ(str1, str2) \ | 339 #define DCHECK_STRCASEEQ(str1, str2) \ |
332 while (false && (str1) == (str2)) NDEBUG_EAT_STREAM_PARAMETERS | 340 while (false && (str1) == (str2)) NDEBUG_EAT_STREAM_PARAMETERS |
333 | 341 |
334 #define DCHECK_STRNE(str1, str2) \ | 342 #define DCHECK_STRNE(str1, str2) \ |
335 while (false && (str1) == (str2)) NDEBUG_EAT_STREAM_PARAMETERS | 343 while (false && (str1) == (str2)) NDEBUG_EAT_STREAM_PARAMETERS |
336 | 344 |
337 #define DCHECK_STRCASENE(str1, str2) \ | 345 #define DCHECK_STRCASENE(str1, str2) \ |
338 while (false && (str1) == (str2)) NDEBUG_EAT_STREAM_PARAMETERS | 346 while (false && (str1) == (str2)) NDEBUG_EAT_STREAM_PARAMETERS |
339 | 347 |
340 #else | 348 #else // OMIT_DLOG_AND_DCHECK |
| 349 |
341 #ifndef NDEBUG | 350 #ifndef NDEBUG |
342 // On a regular debug build, we want to have DCHECKS and DLOGS enabled. | 351 // On a regular debug build, we want to have DCHECKS and DLOGS enabled. |
343 | 352 |
344 #define DLOG(severity) LOG(severity) | 353 #define DLOG(severity) LOG(severity) |
345 #define DLOG_IF(severity, condition) LOG_IF(severity, condition) | 354 #define DLOG_IF(severity, condition) LOG_IF(severity, condition) |
346 #define DLOG_ASSERT(condition) LOG_ASSERT(condition) | 355 #define DLOG_ASSERT(condition) LOG_ASSERT(condition) |
347 | 356 |
348 // debug-only checking. not executed in NDEBUG mode. | 357 // debug-only checking. not executed in NDEBUG mode. |
349 enum { DEBUG_MODE = 1 }; | 358 enum { DEBUG_MODE = 1 }; |
350 #define DCHECK(condition) \ | 359 #define DCHECK(condition) \ |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 // and the other is NULL. To work around this, simply static_cast NULL to the | 492 // and the other is NULL. To work around this, simply static_cast NULL to the |
484 // type of the desired pointer. | 493 // type of the desired pointer. |
485 | 494 |
486 #define DCHECK_EQ(val1, val2) DCHECK_OP(EQ, ==, val1, val2) | 495 #define DCHECK_EQ(val1, val2) DCHECK_OP(EQ, ==, val1, val2) |
487 #define DCHECK_NE(val1, val2) DCHECK_OP(NE, !=, val1, val2) | 496 #define DCHECK_NE(val1, val2) DCHECK_OP(NE, !=, val1, val2) |
488 #define DCHECK_LE(val1, val2) DCHECK_OP(LE, <=, val1, val2) | 497 #define DCHECK_LE(val1, val2) DCHECK_OP(LE, <=, val1, val2) |
489 #define DCHECK_LT(val1, val2) DCHECK_OP(LT, < , val1, val2) | 498 #define DCHECK_LT(val1, val2) DCHECK_OP(LT, < , val1, val2) |
490 #define DCHECK_GE(val1, val2) DCHECK_OP(GE, >=, val1, val2) | 499 #define DCHECK_GE(val1, val2) DCHECK_OP(GE, >=, val1, val2) |
491 #define DCHECK_GT(val1, val2) DCHECK_OP(GT, > , val1, val2) | 500 #define DCHECK_GT(val1, val2) DCHECK_OP(GT, > , val1, val2) |
492 | 501 |
493 #endif // OFFICIAL_BUILD | 502 #endif // OMIT_DLOG_AND_DCHECK |
| 503 #undef OMIT_DLOG_AND_DCHECK |
494 | 504 |
495 #define NOTREACHED() DCHECK(false) | 505 #define NOTREACHED() DCHECK(false) |
496 | 506 |
497 // Redefine the standard assert to use our nice log files | 507 // Redefine the standard assert to use our nice log files |
498 #undef assert | 508 #undef assert |
499 #define assert(x) DLOG_ASSERT(x) | 509 #define assert(x) DLOG_ASSERT(x) |
500 | 510 |
501 // This class more or less represents a particular log message. You | 511 // This class more or less represents a particular log message. You |
502 // create an instance of LogMessage and then stream stuff to it. | 512 // create an instance of LogMessage and then stream stuff to it. |
503 // When you finish streaming to it, ~LogMessage is called and the | 513 // When you finish streaming to it, ~LogMessage is called and the |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 #elif NOTIMPLEMENTED_POLICY == 4 | 652 #elif NOTIMPLEMENTED_POLICY == 4 |
643 #define NOTIMPLEMENTED() LOG(ERROR) << NOTIMPLEMENTED_MSG | 653 #define NOTIMPLEMENTED() LOG(ERROR) << NOTIMPLEMENTED_MSG |
644 #elif NOTIMPLEMENTED_POLICY == 5 | 654 #elif NOTIMPLEMENTED_POLICY == 5 |
645 #define NOTIMPLEMENTED() do {\ | 655 #define NOTIMPLEMENTED() do {\ |
646 static int count = 0;\ | 656 static int count = 0;\ |
647 LOG_IF(ERROR, 0 == count++) << NOTIMPLEMENTED_MSG;\ | 657 LOG_IF(ERROR, 0 == count++) << NOTIMPLEMENTED_MSG;\ |
648 } while(0) | 658 } while(0) |
649 #endif | 659 #endif |
650 | 660 |
651 #endif // BASE_LOGGING_H_ | 661 #endif // BASE_LOGGING_H_ |
OLD | NEW |