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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 BASE_EXPORT LogMessageHandlerFunction GetLogMessageHandler(); | 290 BASE_EXPORT LogMessageHandlerFunction GetLogMessageHandler(); |
291 | 291 |
292 typedef int LogSeverity; | 292 typedef int LogSeverity; |
293 const LogSeverity LOG_VERBOSE = -1; // This is level 1 verbosity | 293 const LogSeverity LOG_VERBOSE = -1; // This is level 1 verbosity |
294 // Note: the log severities are used to index into the array of names, | 294 // Note: the log severities are used to index into the array of names, |
295 // see log_severity_names. | 295 // see log_severity_names. |
296 const LogSeverity LOG_INFO = 0; | 296 const LogSeverity LOG_INFO = 0; |
297 const LogSeverity LOG_WARNING = 1; | 297 const LogSeverity LOG_WARNING = 1; |
298 const LogSeverity LOG_ERROR = 2; | 298 const LogSeverity LOG_ERROR = 2; |
299 const LogSeverity LOG_FATAL = 3; | 299 const LogSeverity LOG_FATAL = 3; |
300 const LogSeverity LOG_NUM_SEVERITIES = 4; | 300 const LogSeverity LOG_DUMP = 4; |
| 301 const LogSeverity LOG_NUM_SEVERITIES = 5; |
301 | 302 |
302 // LOG_DFATAL is LOG_FATAL in debug mode, ERROR in normal mode | 303 // LOG_DFATAL is LOG_FATAL in debug mode, ERROR in normal mode |
303 #ifdef NDEBUG | 304 #if defined(DCHECK_IS_DUMP_WITHOUT_CRASH) |
| 305 const LogSeverity LOG_DFATAL = LOG_DUMP; |
| 306 #elif NDEBUG |
304 const LogSeverity LOG_DFATAL = LOG_ERROR; | 307 const LogSeverity LOG_DFATAL = LOG_ERROR; |
305 #else | 308 #else |
306 const LogSeverity LOG_DFATAL = LOG_FATAL; | 309 const LogSeverity LOG_DFATAL = LOG_FATAL; |
307 #endif | 310 #endif |
308 | 311 |
309 // A few definitions of macros that don't generate much code. These are used | 312 // A few definitions of macros that don't generate much code. These are used |
310 // by LOG() and LOG_IF, etc. Since these are used all over our code, it's | 313 // by LOG() and LOG_IF, etc. Since these are used all over our code, it's |
311 // better to have compact code for these operations. | 314 // better to have compact code for these operations. |
312 #define COMPACT_GOOGLE_LOG_EX_INFO(ClassName, ...) \ | 315 #define COMPACT_GOOGLE_LOG_EX_INFO(ClassName, ...) \ |
313 ::logging::ClassName(__FILE__, __LINE__, ::logging::LOG_INFO, ##__VA_ARGS__) | 316 ::logging::ClassName(__FILE__, __LINE__, ::logging::LOG_INFO, ##__VA_ARGS__) |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 | 690 |
688 #define DVLOG(verboselevel) DVLOG_IF(verboselevel, VLOG_IS_ON(verboselevel)) | 691 #define DVLOG(verboselevel) DVLOG_IF(verboselevel, VLOG_IS_ON(verboselevel)) |
689 | 692 |
690 #define DVPLOG(verboselevel) DVPLOG_IF(verboselevel, VLOG_IS_ON(verboselevel)) | 693 #define DVPLOG(verboselevel) DVPLOG_IF(verboselevel, VLOG_IS_ON(verboselevel)) |
691 | 694 |
692 // Definitions for DCHECK et al. | 695 // Definitions for DCHECK et al. |
693 | 696 |
694 #if DCHECK_IS_ON() | 697 #if DCHECK_IS_ON() |
695 | 698 |
696 #define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \ | 699 #define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \ |
697 COMPACT_GOOGLE_LOG_EX_FATAL(ClassName , ##__VA_ARGS__) | 700 COMPACT_GOOGLE_LOG_EX_DFATAL(ClassName, ##__VA_ARGS__) |
698 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_FATAL | 701 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_DFATAL |
699 const LogSeverity LOG_DCHECK = LOG_FATAL; | 702 const LogSeverity LOG_DCHECK = LOG_DFATAL; |
700 | 703 |
701 #else // DCHECK_IS_ON() | 704 #else // DCHECK_IS_ON() |
702 | 705 |
703 // These are just dummy values. | 706 // These are just dummy values. |
704 #define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \ | 707 #define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \ |
705 COMPACT_GOOGLE_LOG_EX_INFO(ClassName , ##__VA_ARGS__) | 708 COMPACT_GOOGLE_LOG_EX_INFO(ClassName , ##__VA_ARGS__) |
706 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_INFO | 709 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_INFO |
707 const LogSeverity LOG_DCHECK = LOG_INFO; | 710 const LogSeverity LOG_DCHECK = LOG_INFO; |
708 | 711 |
709 #endif // DCHECK_IS_ON() | 712 #endif // DCHECK_IS_ON() |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 LOG_STREAM(DCHECK), \ | 746 LOG_STREAM(DCHECK), \ |
744 DCHECK_IS_ON() ? (logging::AnalyzerNoReturn() || !(condition)) : false) \ | 747 DCHECK_IS_ON() ? (logging::AnalyzerNoReturn() || !(condition)) : false) \ |
745 << "Check failed: " #condition ". " | 748 << "Check failed: " #condition ". " |
746 | 749 |
747 #define DPCHECK(condition) \ | 750 #define DPCHECK(condition) \ |
748 LAZY_STREAM( \ | 751 LAZY_STREAM( \ |
749 PLOG_STREAM(DCHECK), \ | 752 PLOG_STREAM(DCHECK), \ |
750 DCHECK_IS_ON() ? (logging::AnalyzerNoReturn() || !(condition)) : false) \ | 753 DCHECK_IS_ON() ? (logging::AnalyzerNoReturn() || !(condition)) : false) \ |
751 << "Check failed: " #condition ". " | 754 << "Check failed: " #condition ". " |
752 | 755 |
753 #else | 756 #elif DCHECK_IS_ON() && defined(DCHECK_IS_DUMP_WITHOUT_CRASH) |
| 757 // DCHECK is configured to dump-without-crashing, rather than logging. |
| 758 // Since we only intend to enable this in official builds, we follow the |
| 759 // example of CHECK_OP etc in official builds, and strip out logging. |
| 760 // See crbug.com/596231. |
| 761 |
| 762 BASE_EXPORT void DCheckDumpWithoutCrashing(); |
| 763 |
| 764 #define DCHECK(condition) \ |
| 765 !(condition) ? ::logging::DCheckDumpWithoutCrashing() : EAT_STREAM_PARAMETERS |
| 766 |
| 767 #define DPCHECK(condition) DCHECK(condition) |
| 768 |
| 769 #else // DCHECK_IS_ON() && defined(DCHECK_IS_DUMP_WITHOUT_CRASH) |
754 | 770 |
755 #if DCHECK_IS_ON() | 771 #if DCHECK_IS_ON() |
756 | 772 |
757 #define DCHECK(condition) \ | 773 #define DCHECK(condition) \ |
758 LAZY_STREAM(LOG_STREAM(DCHECK), !(condition)) \ | 774 LAZY_STREAM(LOG_STREAM(DCHECK), !(condition)) \ |
759 << "Check failed: " #condition ". " | 775 << "Check failed: " #condition ". " |
760 #define DPCHECK(condition) \ | 776 #define DPCHECK(condition) \ |
761 LAZY_STREAM(PLOG_STREAM(DCHECK), !(condition)) \ | 777 LAZY_STREAM(PLOG_STREAM(DCHECK), !(condition)) \ |
762 << "Check failed: " #condition ". " | 778 << "Check failed: " #condition ". " |
763 | 779 |
764 #else // DCHECK_IS_ON() | 780 #else // DCHECK_IS_ON() |
765 | 781 |
766 #define DCHECK(condition) EAT_STREAM_PARAMETERS << !(condition) | 782 #define DCHECK(condition) EAT_STREAM_PARAMETERS << !(condition) |
767 #define DPCHECK(condition) EAT_STREAM_PARAMETERS << !(condition) | 783 #define DPCHECK(condition) EAT_STREAM_PARAMETERS << !(condition) |
768 | 784 |
769 #endif // DCHECK_IS_ON() | 785 #endif // DCHECK_IS_ON() |
770 | 786 |
771 #endif | 787 #endif // _PREFAST_ |
772 | 788 |
773 // Helper macro for binary operators. | 789 // Helper macro for binary operators. |
774 // Don't use this macro directly in your code, use DCHECK_EQ et al below. | 790 // Don't use this macro directly in your code, use DCHECK_EQ et al below. |
775 // The 'switch' is used to prevent the 'else' from being ambiguous when the | 791 // The 'switch' is used to prevent the 'else' from being ambiguous when the |
776 // macro is used in an 'if' clause such as: | 792 // macro is used in an 'if' clause such as: |
777 // if (a == 1) | 793 // if (a == 1) |
778 // DCHECK_EQ(2, a); | 794 // DCHECK_EQ(2, a); |
779 #if DCHECK_IS_ON() | 795 #if DCHECK_IS_ON() |
780 | 796 |
781 #define DCHECK_OP(name, op, val1, val2) \ | 797 #define DCHECK_OP(name, op, val1, val2) \ |
(...skipping 19 matching lines...) Expand all Loading... |
801 // expansion, this is OK, since the expression is never actually evaluated. | 817 // expansion, this is OK, since the expression is never actually evaluated. |
802 #define DCHECK_OP(name, op, val1, val2) \ | 818 #define DCHECK_OP(name, op, val1, val2) \ |
803 EAT_STREAM_PARAMETERS << (::logging::MakeCheckOpValueString( \ | 819 EAT_STREAM_PARAMETERS << (::logging::MakeCheckOpValueString( \ |
804 ::logging::g_swallow_stream, val1), \ | 820 ::logging::g_swallow_stream, val1), \ |
805 ::logging::MakeCheckOpValueString( \ | 821 ::logging::MakeCheckOpValueString( \ |
806 ::logging::g_swallow_stream, val2), \ | 822 ::logging::g_swallow_stream, val2), \ |
807 (val1)op(val2)) | 823 (val1)op(val2)) |
808 | 824 |
809 #endif // DCHECK_IS_ON() | 825 #endif // DCHECK_IS_ON() |
810 | 826 |
| 827 #endif // DCHECK_IS_ON() && defined(DCHECK_IS_DUMP_WITHOUT_CRASH) |
| 828 |
811 // Equality/Inequality checks - compare two values, and log a | 829 // Equality/Inequality checks - compare two values, and log a |
812 // LOG_DCHECK message including the two values when the result is not | 830 // LOG_DCHECK message including the two values when the result is not |
813 // as expected. The values must have operator<<(ostream, ...) | 831 // as expected. The values must have operator<<(ostream, ...) |
814 // defined. | 832 // defined. |
815 // | 833 // |
816 // You may append to the error message like so: | 834 // You may append to the error message like so: |
817 // DCHECK_NE(1, 2) << "The world must be ending!"; | 835 // DCHECK_NE(1, 2) << "The world must be ending!"; |
818 // | 836 // |
819 // We are very careful to ensure that each argument is evaluated exactly | 837 // We are very careful to ensure that each argument is evaluated exactly |
820 // once, and that anything which is legal to pass as a function argument is | 838 // once, and that anything which is legal to pass as a function argument is |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 #elif NOTIMPLEMENTED_POLICY == 5 | 1089 #elif NOTIMPLEMENTED_POLICY == 5 |
1072 #define NOTIMPLEMENTED() do {\ | 1090 #define NOTIMPLEMENTED() do {\ |
1073 static bool logged_once = false;\ | 1091 static bool logged_once = false;\ |
1074 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ | 1092 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ |
1075 logged_once = true;\ | 1093 logged_once = true;\ |
1076 } while(0);\ | 1094 } while(0);\ |
1077 EAT_STREAM_PARAMETERS | 1095 EAT_STREAM_PARAMETERS |
1078 #endif | 1096 #endif |
1079 | 1097 |
1080 #endif // BASE_LOGGING_H_ | 1098 #endif // BASE_LOGGING_H_ |
OLD | NEW |