OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // Logging and checks. Avoids a dependency on base. | 5 // Logging and checks. Avoids a dependency on base. |
6 // | 6 // |
7 // LOG(tag) prints messages. Tags are INFO, WARNING, ERROR and FATAL. | 7 // LOG(tag) prints messages. Tags are INFO, WARNING, ERROR and FATAL. |
8 // INFO prints to stdout, the others to stderr. FATAL aborts after printing. | 8 // INFO prints to stdout, the others to stderr. FATAL aborts after printing. |
9 // | 9 // |
10 // LOG_IF(tag, predicate) logs if predicate evaluates to true, else silent. | 10 // LOG_IF(tag, predicate) logs if predicate evaluates to true, else silent. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 // Logging streams. Not thread-safe. | 75 // Logging streams. Not thread-safe. |
76 static std::ostream* info_stream_; | 76 static std::ostream* info_stream_; |
77 static std::ostream* error_stream_; | 77 static std::ostream* error_stream_; |
78 }; | 78 }; |
79 | 79 |
80 } // namespace relocation_packer | 80 } // namespace relocation_packer |
81 | 81 |
82 // Make logging severities visible globally. | 82 // Make logging severities visible globally. |
83 typedef relocation_packer::Logger::Severity LogSeverity; | 83 typedef relocation_packer::Logger::Severity LogSeverity; |
84 using LogSeverity::INFO; | |
85 using LogSeverity::WARNING; | |
86 using LogSeverity::ERROR; | |
87 using LogSeverity::FATAL; | |
88 | 84 |
89 // LOG(severity) prints a message with the given severity, and aborts if | 85 // LOG(severity) prints a message with the given severity, and aborts if |
90 // severity is FATAL. LOG_IF(severity, predicate) does the same but only if | 86 // severity is FATAL. LOG_IF(severity, predicate) does the same but only if |
91 // predicate is true. INT_MIN is guaranteed to be less than or equal to | 87 // predicate is true. INT_MIN is guaranteed to be less than or equal to |
92 // any verbosity level. | 88 // any verbosity level. |
93 #define LOG(severity) \ | 89 #define LOG(severity) \ |
94 (relocation_packer::Logger(severity, INT_MIN, true).GetStream()) | 90 (relocation_packer::Logger(relocation_packer::Logger::severity, INT_MIN, \ |
95 #define LOG_IF(severity, predicate) \ | 91 true) \ |
96 (relocation_packer::Logger(severity, INT_MIN, (predicate)).GetStream()) | 92 .GetStream()) |
| 93 #define LOG_IF(severity, predicate) \ |
| 94 (relocation_packer::Logger(relocation_packer::Logger::severity, INT_MIN, \ |
| 95 (predicate)) \ |
| 96 .GetStream()) |
97 | 97 |
98 // VLOG(level) prints its message as INFO if level is less than or equal to | 98 // VLOG(level) prints its message as INFO if level is less than or equal to |
99 // the current verbosity level. | 99 // the current verbosity level. |
100 #define VLOG(level) \ | 100 #define VLOG(level) \ |
101 (relocation_packer::Logger(INFO, (level), true).GetStream()) | 101 (relocation_packer::Logger(relocation_packer::Logger::INFO, (level), true) \ |
102 #define VLOG_IF(level, predicate) \ | 102 .GetStream()) |
103 (relocation_packer::Logger(INFO, (level), (predicate)).GetStream()) | 103 #define VLOG_IF(level, predicate) \ |
| 104 (relocation_packer::Logger(relocation_packer::Logger::INFO, (level), \ |
| 105 (predicate)) \ |
| 106 .GetStream()) |
104 | 107 |
105 // CHECK(predicate) fails with a FATAL log message if predicate is false. | 108 // CHECK(predicate) fails with a FATAL log message if predicate is false. |
106 #define CHECK(predicate) (LOG_IF(FATAL, !(predicate)) \ | 109 #define CHECK(predicate) (LOG_IF(FATAL, !(predicate)) \ |
107 << __FILE__ << ":" << __LINE__ << ": " \ | 110 << __FILE__ << ":" << __LINE__ << ": " \ |
108 << __FUNCTION__ << ": CHECK '" #predicate "' failed") | 111 << __FUNCTION__ << ": CHECK '" #predicate "' failed") |
109 | 112 |
110 // NOTREACHED() always fails with a FATAL log message. | 113 // NOTREACHED() always fails with a FATAL log message. |
111 #define NOTREACHED(_) (LOG(FATAL) \ | 114 #define NOTREACHED(_) (LOG(FATAL) \ |
112 << __FILE__ << ":" << __LINE__ << ": " \ | 115 << __FILE__ << ":" << __LINE__ << ": " \ |
113 << __FUNCTION__ << ": NOTREACHED() hit") | 116 << __FUNCTION__ << ": NOTREACHED() hit") |
114 | 117 |
115 #endif // TOOLS_RELOCATION_PACKER_SRC_DEBUG_H_ | 118 #endif // TOOLS_RELOCATION_PACKER_SRC_DEBUG_H_ |
OLD | NEW |