1 // Copyright 2017 The Chromium Authors
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 PARTITION_ALLOC_PARTITION_ALLOC_BASE_FUCHSIA_FUCHSIA_LOGGING_H_
6 #define PARTITION_ALLOC_PARTITION_ALLOC_BASE_FUCHSIA_FUCHSIA_LOGGING_H_
7
8 #include <lib/fit/function.h>
9 #include <zircon/types.h>
10
11 #include "build/build_config.h"
12 #include "partition_alloc/partition_alloc_base/component_export.h"
13 #include "partition_alloc/partition_alloc_base/debug/debugging_buildflags.h"
14 #include "partition_alloc/partition_alloc_base/logging.h"
15
16 // Use the PA_ZX_LOG family of macros along with a zx_status_t containing a
17 // Zircon error. The error value will be decoded so that logged messages explain
18 // the error.
19
20 namespace partition_alloc::internal::logging {
21
PA_COMPONENT_EXPORT(PARTITION_ALLOC_BASE)22 class PA_COMPONENT_EXPORT(PARTITION_ALLOC_BASE) ZxLogMessage
23 : public logging::LogMessage {
24 public:
25 ZxLogMessage(const char* file_path,
26 int line,
27 LogSeverity severity,
28 zx_status_t zx_err);
29
30 ZxLogMessage(const ZxLogMessage&) = delete;
31 ZxLogMessage& operator=(const ZxLogMessage&) = delete;
32
33 ~ZxLogMessage() override;
34
35 private:
36 zx_status_t zx_err_;
37 };
38
39 } // namespace partition_alloc::internal::logging
40
41 #define PA_ZX_LOG_STREAM(severity, zx_err) \
42 PA_COMPACT_GOOGLE_PLOG_EX_##severity(ZxLogMessage, zx_err).stream()
43
44 #define PA_ZX_LOG(severity, zx_err) \
45 PA_LAZY_STREAM(PA_ZX_LOG_STREAM(severity, zx_err), PA_LOG_IS_ON(severity))
46 #define PA_ZX_LOG_IF(severity, condition, zx_err) \
47 PA_LAZY_STREAM(PA_ZX_LOG_STREAM(severity, zx_err), \
48 PA_LOG_IS_ON(severity) && (condition))
49
50 #define PA_ZX_CHECK(condition, zx_err) \
51 PA_LAZY_STREAM(PA_ZX_LOG_STREAM(FATAL, zx_err), !(condition)) \
52 << "Check failed: " #condition << ". "
53
54 #define PA_ZX_DLOG(severity, zx_err) \
55 PA_LAZY_STREAM(PA_ZX_LOG_STREAM(severity, zx_err), PA_DLOG_IS_ON(severity))
56
57 #if BUILDFLAG(PA_DCHECK_IS_ON)
58 #define PA_ZX_DLOG_IF(severity, condition, zx_err) \
59 PA_LAZY_STREAM(PA_ZX_LOG_STREAM(severity, zx_err), \
60 PA_DLOG_IS_ON(severity) && (condition))
61 #else // BUILDFLAG(PA_DCHECK_IS_ON)
62 #define PA_ZX_DLOG_IF(severity, condition, zx_err) PA_EAT_STREAM_PARAMETERS
63 #endif // BUILDFLAG(PA_DCHECK_IS_ON)
64
65 #define PA_ZX_DCHECK(condition, zx_err) \
66 PA_LAZY_STREAM(PA_ZX_LOG_STREAM(DCHECK, zx_err), \
67 BUILDFLAG(PA_DCHECK_IS_ON) && !(condition)) \
68 << "Check failed: " #condition << ". "
69
70 #endif // PARTITION_ALLOC_PARTITION_ALLOC_BASE_FUCHSIA_FUCHSIA_LOGGING_H_
71