Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <cassert> | 10 #include <cassert> |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 603 #undef DEFINE_CHECK_OP_IMPL | 603 #undef DEFINE_CHECK_OP_IMPL |
| 604 | 604 |
| 605 #define CHECK_EQ(val1, val2) CHECK_OP(EQ, ==, val1, val2) | 605 #define CHECK_EQ(val1, val2) CHECK_OP(EQ, ==, val1, val2) |
| 606 #define CHECK_NE(val1, val2) CHECK_OP(NE, !=, val1, val2) | 606 #define CHECK_NE(val1, val2) CHECK_OP(NE, !=, val1, val2) |
| 607 #define CHECK_LE(val1, val2) CHECK_OP(LE, <=, val1, val2) | 607 #define CHECK_LE(val1, val2) CHECK_OP(LE, <=, val1, val2) |
| 608 #define CHECK_LT(val1, val2) CHECK_OP(LT, < , val1, val2) | 608 #define CHECK_LT(val1, val2) CHECK_OP(LT, < , val1, val2) |
| 609 #define CHECK_GE(val1, val2) CHECK_OP(GE, >=, val1, val2) | 609 #define CHECK_GE(val1, val2) CHECK_OP(GE, >=, val1, val2) |
| 610 #define CHECK_GT(val1, val2) CHECK_OP(GT, > , val1, val2) | 610 #define CHECK_GT(val1, val2) CHECK_OP(GT, > , val1, val2) |
| 611 | 611 |
| 612 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | 612 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
| 613 #define ENABLE_DLOG 0 | |
| 614 #else | |
| 615 #define ENABLE_DLOG 1 | |
| 616 #endif | |
| 617 | |
| 618 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | |
| 619 #define DCHECK_IS_ON() 0 | 613 #define DCHECK_IS_ON() 0 |
| 620 #else | 614 #else |
| 621 #define DCHECK_IS_ON() 1 | 615 #define DCHECK_IS_ON() 1 |
| 622 #endif | 616 #endif |
| 623 | 617 |
| 624 // Definitions for DLOG et al. | 618 // Definitions for DLOG et al. |
| 625 | 619 |
| 626 #if ENABLE_DLOG | 620 #if DCHECK_IS_ON() |
| 627 | 621 |
| 628 #define DLOG_IS_ON(severity) LOG_IS_ON(severity) | 622 #define DLOG_IS_ON(severity) LOG_IS_ON(severity) |
| 629 #define DLOG_IF(severity, condition) LOG_IF(severity, condition) | 623 #define DLOG_IF(severity, condition) LOG_IF(severity, condition) |
| 630 #define DLOG_ASSERT(condition) LOG_ASSERT(condition) | 624 #define DLOG_ASSERT(condition) LOG_ASSERT(condition) |
| 631 #define DPLOG_IF(severity, condition) PLOG_IF(severity, condition) | 625 #define DPLOG_IF(severity, condition) PLOG_IF(severity, condition) |
| 632 #define DVLOG_IF(verboselevel, condition) VLOG_IF(verboselevel, condition) | 626 #define DVLOG_IF(verboselevel, condition) VLOG_IF(verboselevel, condition) |
| 633 #define DVPLOG_IF(verboselevel, condition) VPLOG_IF(verboselevel, condition) | 627 #define DVPLOG_IF(verboselevel, condition) VPLOG_IF(verboselevel, condition) |
| 634 | 628 |
| 635 #else // ENABLE_DLOG | 629 #else // DCHECK_IS_ON() |
| 636 | 630 |
| 637 // If ENABLE_DLOG is off, we want to avoid emitting any references to | 631 // If !DCHECK_IS_ON(), we want to avoid emitting any references to |condition| |
| 638 // |condition| (which may reference a variable defined only if NDEBUG | 632 // (which may reference a variable defined only if NDEBUG is not defined). |
|
danakj
2016/07/20 20:03:03
This comment looks a bit wrong wtf NDBUG right? Sh
gab
2016/07/20 21:01:29
Done.
| |
| 639 // is not defined). Contrast this with DCHECK et al., which has | 633 // Contrast this with DCHECK et al., which has different behavior. |
| 640 // different behavior. | |
| 641 | 634 |
| 642 #define DLOG_IS_ON(severity) false | 635 #define DLOG_IS_ON(severity) false |
| 643 #define DLOG_IF(severity, condition) EAT_STREAM_PARAMETERS | 636 #define DLOG_IF(severity, condition) EAT_STREAM_PARAMETERS |
| 644 #define DLOG_ASSERT(condition) EAT_STREAM_PARAMETERS | 637 #define DLOG_ASSERT(condition) EAT_STREAM_PARAMETERS |
| 645 #define DPLOG_IF(severity, condition) EAT_STREAM_PARAMETERS | 638 #define DPLOG_IF(severity, condition) EAT_STREAM_PARAMETERS |
| 646 #define DVLOG_IF(verboselevel, condition) EAT_STREAM_PARAMETERS | 639 #define DVLOG_IF(verboselevel, condition) EAT_STREAM_PARAMETERS |
| 647 #define DVPLOG_IF(verboselevel, condition) EAT_STREAM_PARAMETERS | 640 #define DVPLOG_IF(verboselevel, condition) EAT_STREAM_PARAMETERS |
| 648 | 641 |
| 649 #endif // ENABLE_DLOG | 642 #endif // DCHECK_IS_ON() |
| 650 | 643 |
| 651 // DEBUG_MODE is for uses like | 644 // DEBUG_MODE is for runtime uses like |
| 652 // if (DEBUG_MODE) foo.CheckThatFoo(); | 645 // if (DEBUG_MODE) foo.CheckThatFoo(); |
| 653 // instead of | 646 // We tie its state to DCHECK_IS_ON(). |
| 654 // #ifndef NDEBUG | |
| 655 // foo.CheckThatFoo(); | |
| 656 // #endif | |
| 657 // | 647 // |
| 658 // We tie its state to ENABLE_DLOG. | 648 // For compile-time checks, #if DCHECK_IS_ON() can be used. |
| 659 enum { DEBUG_MODE = ENABLE_DLOG }; | 649 enum { DEBUG_MODE = DCHECK_IS_ON() }; |
| 660 | |
| 661 #undef ENABLE_DLOG | |
| 662 | 650 |
| 663 #define DLOG(severity) \ | 651 #define DLOG(severity) \ |
| 664 LAZY_STREAM(LOG_STREAM(severity), DLOG_IS_ON(severity)) | 652 LAZY_STREAM(LOG_STREAM(severity), DLOG_IS_ON(severity)) |
| 665 | 653 |
| 666 #define DPLOG(severity) \ | 654 #define DPLOG(severity) \ |
| 667 LAZY_STREAM(PLOG_STREAM(severity), DLOG_IS_ON(severity)) | 655 LAZY_STREAM(PLOG_STREAM(severity), DLOG_IS_ON(severity)) |
| 668 | 656 |
| 669 #define DVLOG(verboselevel) DVLOG_IF(verboselevel, VLOG_IS_ON(verboselevel)) | 657 #define DVLOG(verboselevel) DVLOG_IF(verboselevel, VLOG_IS_ON(verboselevel)) |
| 670 | 658 |
| 671 #define DVPLOG(verboselevel) DVPLOG_IF(verboselevel, VLOG_IS_ON(verboselevel)) | 659 #define DVPLOG(verboselevel) DVPLOG_IF(verboselevel, VLOG_IS_ON(verboselevel)) |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 994 #elif NOTIMPLEMENTED_POLICY == 5 | 982 #elif NOTIMPLEMENTED_POLICY == 5 |
| 995 #define NOTIMPLEMENTED() do {\ | 983 #define NOTIMPLEMENTED() do {\ |
| 996 static bool logged_once = false;\ | 984 static bool logged_once = false;\ |
| 997 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ | 985 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ |
| 998 logged_once = true;\ | 986 logged_once = true;\ |
| 999 } while(0);\ | 987 } while(0);\ |
| 1000 EAT_STREAM_PARAMETERS | 988 EAT_STREAM_PARAMETERS |
| 1001 #endif | 989 #endif |
| 1002 | 990 |
| 1003 #endif // BASE_LOGGING_H_ | 991 #endif // BASE_LOGGING_H_ |
| OLD | NEW |