| 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 <cassert> | 8 #include <cassert> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <cstring> | 10 #include <cstring> |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 #define CHECK_GE(val1, val2) CHECK_OP(GE, >=, val1, val2) | 568 #define CHECK_GE(val1, val2) CHECK_OP(GE, >=, val1, val2) |
| 569 #define CHECK_GT(val1, val2) CHECK_OP(GT, > , val1, val2) | 569 #define CHECK_GT(val1, val2) CHECK_OP(GT, > , val1, val2) |
| 570 | 570 |
| 571 #if defined(NDEBUG) | 571 #if defined(NDEBUG) |
| 572 #define ENABLE_DLOG 0 | 572 #define ENABLE_DLOG 0 |
| 573 #else | 573 #else |
| 574 #define ENABLE_DLOG 1 | 574 #define ENABLE_DLOG 1 |
| 575 #endif | 575 #endif |
| 576 | 576 |
| 577 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | 577 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
| 578 #define ENABLE_DCHECK 0 | 578 #define DCHECK_IS_ON 0 |
| 579 #else | 579 #else |
| 580 #define ENABLE_DCHECK 1 | 580 #define DCHECK_IS_ON 1 |
| 581 #endif | 581 #endif |
| 582 | 582 |
| 583 // Definitions for DLOG et al. | 583 // Definitions for DLOG et al. |
| 584 | 584 |
| 585 #if ENABLE_DLOG | 585 #if ENABLE_DLOG |
| 586 | 586 |
| 587 #define DLOG_IS_ON(severity) LOG_IS_ON(severity) | 587 #define DLOG_IS_ON(severity) LOG_IS_ON(severity) |
| 588 #define DLOG_IF(severity, condition) LOG_IF(severity, condition) | 588 #define DLOG_IF(severity, condition) LOG_IF(severity, condition) |
| 589 #define DLOG_ASSERT(condition) LOG_ASSERT(condition) | 589 #define DLOG_ASSERT(condition) LOG_ASSERT(condition) |
| 590 #define DPLOG_IF(severity, condition) PLOG_IF(severity, condition) | 590 #define DPLOG_IF(severity, condition) PLOG_IF(severity, condition) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 | 635 |
| 636 #define DPLOG(severity) \ | 636 #define DPLOG(severity) \ |
| 637 LAZY_STREAM(PLOG_STREAM(severity), DLOG_IS_ON(severity)) | 637 LAZY_STREAM(PLOG_STREAM(severity), DLOG_IS_ON(severity)) |
| 638 | 638 |
| 639 #define DVLOG(verboselevel) DVLOG_IF(verboselevel, VLOG_IS_ON(verboselevel)) | 639 #define DVLOG(verboselevel) DVLOG_IF(verboselevel, VLOG_IS_ON(verboselevel)) |
| 640 | 640 |
| 641 #define DVPLOG(verboselevel) DVPLOG_IF(verboselevel, VLOG_IS_ON(verboselevel)) | 641 #define DVPLOG(verboselevel) DVPLOG_IF(verboselevel, VLOG_IS_ON(verboselevel)) |
| 642 | 642 |
| 643 // Definitions for DCHECK et al. | 643 // Definitions for DCHECK et al. |
| 644 | 644 |
| 645 #if ENABLE_DCHECK | 645 #if DCHECK_IS_ON |
| 646 | 646 |
| 647 #define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \ | 647 #define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \ |
| 648 COMPACT_GOOGLE_LOG_EX_FATAL(ClassName , ##__VA_ARGS__) | 648 COMPACT_GOOGLE_LOG_EX_FATAL(ClassName , ##__VA_ARGS__) |
| 649 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_FATAL | 649 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_FATAL |
| 650 const LogSeverity LOG_DCHECK = LOG_FATAL; | 650 const LogSeverity LOG_DCHECK = LOG_FATAL; |
| 651 #define DCHECK_IS_ON() true | |
| 652 | 651 |
| 653 #else // ENABLE_DCHECK | 652 #else // DCHECK_IS_ON |
| 654 | 653 |
| 655 // These are just dummy values since DCHECK_IS_ON() is always false in | 654 // These are just dummy values. |
| 656 // this case. | |
| 657 #define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \ | 655 #define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \ |
| 658 COMPACT_GOOGLE_LOG_EX_INFO(ClassName , ##__VA_ARGS__) | 656 COMPACT_GOOGLE_LOG_EX_INFO(ClassName , ##__VA_ARGS__) |
| 659 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_INFO | 657 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_INFO |
| 660 const LogSeverity LOG_DCHECK = LOG_INFO; | 658 const LogSeverity LOG_DCHECK = LOG_INFO; |
| 661 #define DCHECK_IS_ON() false | |
| 662 | 659 |
| 663 #endif // ENABLE_DCHECK | 660 #endif // DCHECK_IS_ON |
| 664 #undef ENABLE_DCHECK | |
| 665 | 661 |
| 666 // DCHECK et al. make sure to reference |condition| regardless of | 662 // DCHECK et al. make sure to reference |condition| regardless of |
| 667 // whether DCHECKs are enabled; this is so that we don't get unused | 663 // whether DCHECKs are enabled; this is so that we don't get unused |
| 668 // variable warnings if the only use of a variable is in a DCHECK. | 664 // variable warnings if the only use of a variable is in a DCHECK. |
| 669 // This behavior is different from DLOG_IF et al. | 665 // This behavior is different from DLOG_IF et al. |
| 670 | 666 |
| 671 #define DCHECK(condition) \ | 667 #define DCHECK(condition) \ |
| 672 LAZY_STREAM(LOG_STREAM(DCHECK), DCHECK_IS_ON() && !(condition)) \ | 668 LAZY_STREAM(LOG_STREAM(DCHECK), DCHECK_IS_ON && !(condition)) \ |
| 673 << "Check failed: " #condition ". " | 669 << "Check failed: " #condition ". " |
| 674 | 670 |
| 675 #define DPCHECK(condition) \ | 671 #define DPCHECK(condition) \ |
| 676 LAZY_STREAM(PLOG_STREAM(DCHECK), DCHECK_IS_ON() && !(condition)) \ | 672 LAZY_STREAM(PLOG_STREAM(DCHECK), DCHECK_IS_ON && !(condition)) \ |
| 677 << "Check failed: " #condition ". " | 673 << "Check failed: " #condition ". " |
| 678 | 674 |
| 679 // Helper macro for binary operators. | 675 // Helper macro for binary operators. |
| 680 // Don't use this macro directly in your code, use DCHECK_EQ et al below. | 676 // Don't use this macro directly in your code, use DCHECK_EQ et al below. |
| 681 #define DCHECK_OP(name, op, val1, val2) \ | 677 #define DCHECK_OP(name, op, val1, val2) \ |
| 682 if (DCHECK_IS_ON()) \ | 678 if (DCHECK_IS_ON) \ |
| 683 if (std::string* _result = \ | 679 if (std::string* _result = \ |
| 684 logging::Check##name##Impl((val1), (val2), \ | 680 logging::Check##name##Impl((val1), (val2), \ |
| 685 #val1 " " #op " " #val2)) \ | 681 #val1 " " #op " " #val2)) \ |
| 686 logging::LogMessage( \ | 682 logging::LogMessage( \ |
| 687 __FILE__, __LINE__, ::logging::LOG_DCHECK, \ | 683 __FILE__, __LINE__, ::logging::LOG_DCHECK, \ |
| 688 _result).stream() | 684 _result).stream() |
| 689 | 685 |
| 690 // Equality/Inequality checks - compare two values, and log a | 686 // Equality/Inequality checks - compare two values, and log a |
| 691 // LOG_DCHECK message including the two values when the result is not | 687 // LOG_DCHECK message including the two values when the result is not |
| 692 // as expected. The values must have operator<<(ostream, ...) | 688 // as expected. The values must have operator<<(ostream, ...) |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 #elif NOTIMPLEMENTED_POLICY == 5 | 951 #elif NOTIMPLEMENTED_POLICY == 5 |
| 956 #define NOTIMPLEMENTED() do {\ | 952 #define NOTIMPLEMENTED() do {\ |
| 957 static bool logged_once = false;\ | 953 static bool logged_once = false;\ |
| 958 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ | 954 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ |
| 959 logged_once = true;\ | 955 logged_once = true;\ |
| 960 } while(0);\ | 956 } while(0);\ |
| 961 EAT_STREAM_PARAMETERS | 957 EAT_STREAM_PARAMETERS |
| 962 #endif | 958 #endif |
| 963 | 959 |
| 964 #endif // BASE_LOGGING_H_ | 960 #endif // BASE_LOGGING_H_ |
| OLD | NEW |