| 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. |
| 11 // | 11 // |
| 12 // VLOG(level) logs INFO messages where level is less than or equal to the | 12 // VLOG(level) logs INFO messages where level is less than or equal to the |
| 13 // verbosity level set with SetVerbose(). | 13 // verbosity level set with SetVerbose(). |
| 14 // | 14 // |
| 15 // VLOG_IF(level, predicate) logs INFO if predicate evaluates to true, | 15 // VLOG_IF(level, predicate) logs INFO if predicate evaluates to true, |
| 16 // else silent. | 16 // else silent. |
| 17 // | 17 // |
| 18 // CHECK(predicate) logs a FATAL error if predicate is false. | 18 // CHECK(predicate) logs a FATAL error if predicate is false. |
| 19 // NOTREACHED() always aborts. | 19 // NOTREACHED() always aborts. |
| 20 // Log streams can be changed with SetStreams(). Logging is not thread-safe. | 20 // Log streams can be changed with SetStreams(). Logging is not thread-safe. |
| 21 // | 21 // |
| 22 | 22 |
| 23 #ifndef TOOLS_RELOCATION_PACKER_SRC_DEBUG_H_ | 23 #ifndef TOOLS_RELOCATION_PACKER_SRC_DEBUG_H_ |
| 24 #define TOOLS_RELOCATION_PACKER_SRC_DEBUG_H_ | 24 #define TOOLS_RELOCATION_PACKER_SRC_DEBUG_H_ |
| 25 | 25 |
| 26 #include <limits.h> | 26 #include <limits.h> |
| 27 #include <algorithm> | |
| 28 #include <ostream> | 27 #include <ostream> |
| 29 #include <sstream> | 28 #include <sstream> |
| 30 | 29 |
| 31 namespace relocation_packer { | 30 namespace relocation_packer { |
| 32 | 31 |
| 33 class Logger { | 32 class Logger { |
| 34 public: | 33 public: |
| 35 enum Severity {INFO = 0, WARNING, ERROR, FATAL}; | 34 enum Severity {INFO = 0, WARNING, ERROR, FATAL}; |
| 36 | 35 |
| 37 // Construct a new message logger. Prints if level is less than or | 36 // Construct a new message logger. Prints if level is less than or |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 #define CHECK(predicate) (LOG_IF(FATAL, !(predicate)) \ | 106 #define CHECK(predicate) (LOG_IF(FATAL, !(predicate)) \ |
| 108 << __FILE__ << ":" << __LINE__ << ": " \ | 107 << __FILE__ << ":" << __LINE__ << ": " \ |
| 109 << __FUNCTION__ << ": CHECK '" #predicate "' failed") | 108 << __FUNCTION__ << ": CHECK '" #predicate "' failed") |
| 110 | 109 |
| 111 // NOTREACHED() always fails with a FATAL log message. | 110 // NOTREACHED() always fails with a FATAL log message. |
| 112 #define NOTREACHED(_) (LOG(FATAL) \ | 111 #define NOTREACHED(_) (LOG(FATAL) \ |
| 113 << __FILE__ << ":" << __LINE__ << ": " \ | 112 << __FILE__ << ":" << __LINE__ << ": " \ |
| 114 << __FUNCTION__ << ": NOTREACHED() hit") | 113 << __FUNCTION__ << ": NOTREACHED() hit") |
| 115 | 114 |
| 116 #endif // TOOLS_RELOCATION_PACKER_SRC_DEBUG_H_ | 115 #endif // TOOLS_RELOCATION_PACKER_SRC_DEBUG_H_ |
| OLD | NEW |