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; | 84 static const LogSeverity INFO = LogSeverity::INFO; |
85 using LogSeverity::WARNING; | 85 static const LogSeverity WARNING = LogSeverity::WARNING; |
86 using LogSeverity::ERROR; | 86 static const LogSeverity ERROR = LogSeverity::ERROR; |
87 using LogSeverity::FATAL; | 87 static const LogSeverity FATAL = LogSeverity::FATAL; |
88 | 88 |
89 // LOG(severity) prints a message with the given severity, and aborts if | 89 // 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 | 90 // 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 | 91 // predicate is true. INT_MIN is guaranteed to be less than or equal to |
92 // any verbosity level. | 92 // any verbosity level. |
93 #define LOG(severity) \ | 93 #define LOG(severity) \ |
94 (relocation_packer::Logger(severity, INT_MIN, true).GetStream()) | 94 (relocation_packer::Logger(severity, INT_MIN, true).GetStream()) |
95 #define LOG_IF(severity, predicate) \ | 95 #define LOG_IF(severity, predicate) \ |
96 (relocation_packer::Logger(severity, INT_MIN, (predicate)).GetStream()) | 96 (relocation_packer::Logger(severity, INT_MIN, (predicate)).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(INFO, (level), true).GetStream()) |
102 #define VLOG_IF(level, predicate) \ | 102 #define VLOG_IF(level, predicate) \ |
103 (relocation_packer::Logger(INFO, (level), (predicate)).GetStream()) | 103 (relocation_packer::Logger(INFO, (level), (predicate)).GetStream()) |
104 | 104 |
105 // CHECK(predicate) fails with a FATAL log message if predicate is false. | 105 // CHECK(predicate) fails with a FATAL log message if predicate is false. |
106 #define CHECK(predicate) (LOG_IF(FATAL, !(predicate)) \ | 106 #define CHECK(predicate) (LOG_IF(FATAL, !(predicate)) \ |
107 << __FILE__ << ":" << __LINE__ << ": " \ | 107 << __FILE__ << ":" << __LINE__ << ": " \ |
108 << __FUNCTION__ << ": CHECK '" #predicate "' failed") | 108 << __FUNCTION__ << ": CHECK '" #predicate "' failed") |
109 | 109 |
110 // NOTREACHED() always fails with a FATAL log message. | 110 // NOTREACHED() always fails with a FATAL log message. |
111 #define NOTREACHED(_) (LOG(FATAL) \ | 111 #define NOTREACHED(_) (LOG(FATAL) \ |
112 << __FILE__ << ":" << __LINE__ << ": " \ | 112 << __FILE__ << ":" << __LINE__ << ": " \ |
113 << __FUNCTION__ << ": NOTREACHED() hit") | 113 << __FUNCTION__ << ": NOTREACHED() hit") |
114 | 114 |
115 #endif // TOOLS_RELOCATION_PACKER_SRC_DEBUG_H_ | 115 #endif // TOOLS_RELOCATION_PACKER_SRC_DEBUG_H_ |
OLD | NEW |