Andrew Top | 0d1858f | 2019-05-15 22:01:47 -0700 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BASE_FUCHSIA_FUCHSIA_LOGGING_H_ |
| 6 | #define BASE_FUCHSIA_FUCHSIA_LOGGING_H_ |
| 7 | |
| 8 | #include <zircon/types.h> |
| 9 | |
| 10 | #include "base/base_export.h" |
| 11 | #include "base/logging.h" |
| 12 | #include "base/macros.h" |
| 13 | #include "build/build_config.h" |
| 14 | #include "starboard/types.h" |
| 15 | |
| 16 | // Use the ZX_LOG family of macros along with a zx_status_t containing a Zircon |
| 17 | // error. The error value will be decoded so that logged messages explain the |
| 18 | // error. |
| 19 | |
| 20 | namespace logging { |
| 21 | |
| 22 | class BASE_EXPORT ZxLogMessage : public logging::LogMessage { |
| 23 | public: |
| 24 | ZxLogMessage(const char* file_path, |
| 25 | int line, |
| 26 | LogSeverity severity, |
| 27 | zx_status_t zx_err); |
| 28 | ~ZxLogMessage(); |
| 29 | |
| 30 | private: |
| 31 | zx_status_t zx_err_; |
| 32 | |
| 33 | DISALLOW_COPY_AND_ASSIGN(ZxLogMessage); |
| 34 | }; |
| 35 | |
| 36 | } // namespace logging |
| 37 | |
| 38 | #define ZX_LOG_STREAM(severity, zx_err) \ |
| 39 | COMPACT_GOOGLE_LOG_EX_##severity(ZxLogMessage, zx_err).stream() |
| 40 | |
| 41 | #define ZX_LOG(severity, zx_err) \ |
| 42 | LAZY_STREAM(ZX_LOG_STREAM(severity, zx_err), LOG_IS_ON(severity)) |
| 43 | #define ZX_LOG_IF(severity, condition, zx_err) \ |
| 44 | LAZY_STREAM(ZX_LOG_STREAM(severity, zx_err), \ |
| 45 | LOG_IS_ON(severity) && (condition)) |
| 46 | |
| 47 | #define ZX_CHECK(condition, zx_err) \ |
| 48 | LAZY_STREAM(ZX_LOG_STREAM(FATAL, zx_err), !(condition)) \ |
| 49 | << "Check failed: " #condition << ". " |
| 50 | |
| 51 | #define ZX_DLOG(severity, zx_err) \ |
| 52 | LAZY_STREAM(ZX_LOG_STREAM(severity, zx_err), DLOG_IS_ON(severity)) |
| 53 | |
| 54 | #if DCHECK_IS_ON() |
| 55 | #define ZX_DLOG_IF(severity, condition, zx_err) \ |
| 56 | LAZY_STREAM(ZX_LOG_STREAM(severity, zx_err), \ |
| 57 | DLOG_IS_ON(severity) && (condition)) |
| 58 | #else // DCHECK_IS_ON() |
| 59 | #define ZX_DLOG_IF(severity, condition, zx_err) EAT_STREAM_PARAMETERS |
| 60 | #endif // DCHECK_IS_ON() |
| 61 | |
| 62 | #define ZX_DCHECK(condition, zx_err) \ |
| 63 | LAZY_STREAM(ZX_LOG_STREAM(DCHECK, zx_err), DCHECK_IS_ON() && !(condition)) \ |
| 64 | << "Check failed: " #condition << ". " |
| 65 | |
| 66 | #endif // BASE_FUCHSIA_FUCHSIA_LOGGING_H_ |