Upload upstream chromium 76.0.3809.146
[platform/framework/web/chromium-efl.git] / base / fuchsia / fuchsia_logging.h
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
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
17 // error.
18
19 namespace logging {
20
21 class BASE_EXPORT ZxLogMessage : public logging::LogMessage {
22  public:
23   ZxLogMessage(const char* file_path,
24                int line,
25                LogSeverity severity,
26                zx_status_t zx_err);
27   ~ZxLogMessage();
28
29  private:
30   zx_status_t zx_err_;
31
32   DISALLOW_COPY_AND_ASSIGN(ZxLogMessage);
33 };
34
35 }  // namespace logging
36
37 #define ZX_LOG_STREAM(severity, zx_err) \
38   COMPACT_GOOGLE_LOG_EX_##severity(ZxLogMessage, zx_err).stream()
39
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))
45
46 #define ZX_CHECK(condition, zx_err)                       \
47   LAZY_STREAM(ZX_LOG_STREAM(FATAL, zx_err), !(condition)) \
48       << "Check failed: " #condition << ". "
49
50 #define ZX_DLOG(severity, zx_err) \
51   LAZY_STREAM(ZX_LOG_STREAM(severity, zx_err), DLOG_IS_ON(severity))
52
53 #if DCHECK_IS_ON()
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()
60
61 #define ZX_DCHECK(condition, zx_err)                                         \
62   LAZY_STREAM(ZX_LOG_STREAM(DCHECK, zx_err), DCHECK_IS_ON() && !(condition)) \
63       << "Check failed: " #condition << ". "
64
65 #endif  // BASE_FUCHSIA_FUCHSIA_LOGGING_H_