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.
5 #ifndef BASE_FUCHSIA_FUCHSIA_LOGGING_H_
6 #define BASE_FUCHSIA_FUCHSIA_LOGGING_H_
8 #include <zircon/types.h>
10 #include "base/base_export.h"
11 #include "base/logging.h"
12 #include "base/macros.h"
13 #include "build/build_config.h"
15 // Use the ZX_LOG family of macros along with a zx_status_t containing a Zircon
16 // error. The error value will be decoded so that logged messages explain the
21 class BASE_EXPORT ZxLogMessage : public logging::LogMessage {
23 ZxLogMessage(const char* file_path,
32 DISALLOW_COPY_AND_ASSIGN(ZxLogMessage);
35 } // namespace logging
37 #define ZX_LOG_STREAM(severity, zx_err) \
38 COMPACT_GOOGLE_LOG_EX_##severity(ZxLogMessage, zx_err).stream()
40 #define ZX_LOG(severity, zx_err) \
41 LAZY_STREAM(ZX_LOG_STREAM(severity, zx_err), LOG_IS_ON(severity))
42 #define ZX_LOG_IF(severity, condition, zx_err) \
43 LAZY_STREAM(ZX_LOG_STREAM(severity, zx_err), \
44 LOG_IS_ON(severity) && (condition))
46 #define ZX_CHECK(condition, zx_err) \
47 LAZY_STREAM(ZX_LOG_STREAM(FATAL, zx_err), !(condition)) \
48 << "Check failed: " #condition << ". "
50 #define ZX_DLOG(severity, zx_err) \
51 LAZY_STREAM(ZX_LOG_STREAM(severity, zx_err), DLOG_IS_ON(severity))
54 #define ZX_DLOG_IF(severity, condition, zx_err) \
55 LAZY_STREAM(ZX_LOG_STREAM(severity, zx_err), \
56 DLOG_IS_ON(severity) && (condition))
57 #else // DCHECK_IS_ON()
58 #define ZX_DLOG_IF(severity, condition, zx_err) EAT_STREAM_PARAMETERS
59 #endif // DCHECK_IS_ON()
61 #define ZX_DCHECK(condition, zx_err) \
62 LAZY_STREAM(ZX_LOG_STREAM(DCHECK, zx_err), DCHECK_IS_ON() && !(condition)) \
63 << "Check failed: " #condition << ". "
65 #endif // BASE_FUCHSIA_FUCHSIA_LOGGING_H_