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