xref: /aosp_15_r20/external/angle/third_party/abseil-cpp/absl/log/internal/strip.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 // Copyright 2022 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // -----------------------------------------------------------------------------
16 // File: log/internal/strip.h
17 // -----------------------------------------------------------------------------
18 //
19 
20 #ifndef ABSL_LOG_INTERNAL_STRIP_H_
21 #define ABSL_LOG_INTERNAL_STRIP_H_
22 
23 #include "absl/base/attributes.h"  // IWYU pragma: keep
24 #include "absl/base/log_severity.h"
25 #include "absl/log/internal/log_message.h"
26 #include "absl/log/internal/nullstream.h"
27 
28 // `ABSL_LOGGING_INTERNAL_LOG_*` evaluates to a temporary `LogMessage` object or
29 // to a related object with a compatible API but different behavior.  This set
30 // of defines comes in three flavors: vanilla, plus two variants that strip some
31 // logging in subtly different ways for subtly different reasons (see below).
32 #if defined(STRIP_LOG) && STRIP_LOG
33 
34 // Attribute for marking variables used in implementation details of logging
35 // macros as unused, but only when `STRIP_LOG` is defined.
36 // With `STRIP_LOG` on, not marking them triggers `-Wunused-but-set-variable`,
37 // With `STRIP_LOG` off, marking them triggers `-Wused-but-marked-unused`.
38 //
39 // TODO(b/290784225): Replace this macro with attribute [[maybe_unused]] when
40 // Abseil stops supporting C++14.
41 #define ABSL_LOG_INTERNAL_ATTRIBUTE_UNUSED_IF_STRIP_LOG ABSL_ATTRIBUTE_UNUSED
42 
43 #define ABSL_LOGGING_INTERNAL_LOG_INFO ::absl::log_internal::NullStream()
44 #define ABSL_LOGGING_INTERNAL_LOG_WARNING ::absl::log_internal::NullStream()
45 #define ABSL_LOGGING_INTERNAL_LOG_ERROR ::absl::log_internal::NullStream()
46 #define ABSL_LOGGING_INTERNAL_LOG_FATAL ::absl::log_internal::NullStreamFatal()
47 #define ABSL_LOGGING_INTERNAL_LOG_QFATAL ::absl::log_internal::NullStreamFatal()
48 #define ABSL_LOGGING_INTERNAL_LOG_DFATAL \
49   ::absl::log_internal::NullStreamMaybeFatal(::absl::kLogDebugFatal)
50 #define ABSL_LOGGING_INTERNAL_LOG_LEVEL(severity) \
51   ::absl::log_internal::NullStreamMaybeFatal(absl_log_internal_severity)
52 
53 // Fatal `DLOG`s expand a little differently to avoid being `[[noreturn]]`.
54 #define ABSL_LOGGING_INTERNAL_DLOG_FATAL \
55   ::absl::log_internal::NullStreamMaybeFatal(::absl::LogSeverity::kFatal)
56 #define ABSL_LOGGING_INTERNAL_DLOG_QFATAL \
57   ::absl::log_internal::NullStreamMaybeFatal(::absl::LogSeverity::kFatal)
58 
59 #define ABSL_LOG_INTERNAL_CHECK(failure_message) ABSL_LOGGING_INTERNAL_LOG_FATAL
60 #define ABSL_LOG_INTERNAL_QCHECK(failure_message) \
61   ABSL_LOGGING_INTERNAL_LOG_QFATAL
62 
63 #else  // !defined(STRIP_LOG) || !STRIP_LOG
64 
65 #define ABSL_LOG_INTERNAL_ATTRIBUTE_UNUSED_IF_STRIP_LOG
66 
67 #define ABSL_LOGGING_INTERNAL_LOG_INFO \
68   ::absl::log_internal::LogMessage(    \
69       __FILE__, __LINE__, ::absl::log_internal::LogMessage::InfoTag{})
70 #define ABSL_LOGGING_INTERNAL_LOG_WARNING \
71   ::absl::log_internal::LogMessage(       \
72       __FILE__, __LINE__, ::absl::log_internal::LogMessage::WarningTag{})
73 #define ABSL_LOGGING_INTERNAL_LOG_ERROR \
74   ::absl::log_internal::LogMessage(     \
75       __FILE__, __LINE__, ::absl::log_internal::LogMessage::ErrorTag{})
76 #define ABSL_LOGGING_INTERNAL_LOG_FATAL \
77   ::absl::log_internal::LogMessageFatal(__FILE__, __LINE__)
78 #define ABSL_LOGGING_INTERNAL_LOG_QFATAL \
79   ::absl::log_internal::LogMessageQuietlyFatal(__FILE__, __LINE__)
80 #define ABSL_LOGGING_INTERNAL_LOG_DFATAL \
81   ::absl::log_internal::LogMessage(__FILE__, __LINE__, ::absl::kLogDebugFatal)
82 #define ABSL_LOGGING_INTERNAL_LOG_LEVEL(severity)      \
83   ::absl::log_internal::LogMessage(__FILE__, __LINE__, \
84                                    absl_log_internal_severity)
85 
86 // Fatal `DLOG`s expand a little differently to avoid being `[[noreturn]]`.
87 #define ABSL_LOGGING_INTERNAL_DLOG_FATAL \
88   ::absl::log_internal::LogMessageDebugFatal(__FILE__, __LINE__)
89 #define ABSL_LOGGING_INTERNAL_DLOG_QFATAL \
90   ::absl::log_internal::LogMessageQuietlyDebugFatal(__FILE__, __LINE__)
91 
92 // These special cases dispatch to special-case constructors that allow us to
93 // avoid an extra function call and shrink non-LTO binaries by a percent or so.
94 #define ABSL_LOG_INTERNAL_CHECK(failure_message) \
95   ::absl::log_internal::LogMessageFatal(__FILE__, __LINE__, failure_message)
96 #define ABSL_LOG_INTERNAL_QCHECK(failure_message)                  \
97   ::absl::log_internal::LogMessageQuietlyFatal(__FILE__, __LINE__, \
98                                                failure_message)
99 #endif  // !defined(STRIP_LOG) || !STRIP_LOG
100 
101 // This part of a non-fatal `DLOG`s expands the same as `LOG`.
102 #define ABSL_LOGGING_INTERNAL_DLOG_INFO ABSL_LOGGING_INTERNAL_LOG_INFO
103 #define ABSL_LOGGING_INTERNAL_DLOG_WARNING ABSL_LOGGING_INTERNAL_LOG_WARNING
104 #define ABSL_LOGGING_INTERNAL_DLOG_ERROR ABSL_LOGGING_INTERNAL_LOG_ERROR
105 #define ABSL_LOGGING_INTERNAL_DLOG_DFATAL ABSL_LOGGING_INTERNAL_LOG_DFATAL
106 #define ABSL_LOGGING_INTERNAL_DLOG_LEVEL ABSL_LOGGING_INTERNAL_LOG_LEVEL
107 
108 #endif  // ABSL_LOG_INTERNAL_STRIP_H_
109