Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:40:53

0001 // Copyright 2022 The Abseil Authors.
0002 //
0003 // Licensed under the Apache License, Version 2.0 (the "License");
0004 // you may not use this file except in compliance with the License.
0005 // You may obtain a copy of the License at
0006 //
0007 //      https://www.apache.org/licenses/LICENSE-2.0
0008 //
0009 // Unless required by applicable law or agreed to in writing, software
0010 // distributed under the License is distributed on an "AS IS" BASIS,
0011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0012 // See the License for the specific language governing permissions and
0013 // limitations under the License.
0014 //
0015 // -----------------------------------------------------------------------------
0016 // File: log/internal/strip.h
0017 // -----------------------------------------------------------------------------
0018 //
0019 
0020 #ifndef ABSL_LOG_INTERNAL_STRIP_H_
0021 #define ABSL_LOG_INTERNAL_STRIP_H_
0022 
0023 #include "absl/base/attributes.h"  // IWYU pragma: keep
0024 #include "absl/base/log_severity.h"
0025 #include "absl/log/internal/log_message.h"
0026 #include "absl/log/internal/nullstream.h"
0027 
0028 // `ABSL_LOGGING_INTERNAL_LOG_*` evaluates to a temporary `LogMessage` object or
0029 // to a related object with a compatible API but different behavior.  This set
0030 // of defines comes in three flavors: vanilla, plus two variants that strip some
0031 // logging in subtly different ways for subtly different reasons (see below).
0032 #if defined(STRIP_LOG) && STRIP_LOG
0033 
0034 // Attribute for marking variables used in implementation details of logging
0035 // macros as unused, but only when `STRIP_LOG` is defined.
0036 // With `STRIP_LOG` on, not marking them triggers `-Wunused-but-set-variable`,
0037 // With `STRIP_LOG` off, marking them triggers `-Wused-but-marked-unused`.
0038 //
0039 // TODO(b/290784225): Replace this macro with attribute [[maybe_unused]] when
0040 // Abseil stops supporting C++14.
0041 #define ABSL_LOG_INTERNAL_ATTRIBUTE_UNUSED_IF_STRIP_LOG ABSL_ATTRIBUTE_UNUSED
0042 
0043 #define ABSL_LOGGING_INTERNAL_LOG_INFO ::absl::log_internal::NullStream()
0044 #define ABSL_LOGGING_INTERNAL_LOG_WARNING ::absl::log_internal::NullStream()
0045 #define ABSL_LOGGING_INTERNAL_LOG_ERROR ::absl::log_internal::NullStream()
0046 #define ABSL_LOGGING_INTERNAL_LOG_FATAL ::absl::log_internal::NullStreamFatal()
0047 #define ABSL_LOGGING_INTERNAL_LOG_QFATAL ::absl::log_internal::NullStreamFatal()
0048 #define ABSL_LOGGING_INTERNAL_LOG_DFATAL \
0049   ::absl::log_internal::NullStreamMaybeFatal(::absl::kLogDebugFatal)
0050 #define ABSL_LOGGING_INTERNAL_LOG_LEVEL(severity) \
0051   ::absl::log_internal::NullStreamMaybeFatal(absl_log_internal_severity)
0052 
0053 // Fatal `DLOG`s expand a little differently to avoid being `[[noreturn]]`.
0054 #define ABSL_LOGGING_INTERNAL_DLOG_FATAL \
0055   ::absl::log_internal::NullStreamMaybeFatal(::absl::LogSeverity::kFatal)
0056 #define ABSL_LOGGING_INTERNAL_DLOG_QFATAL \
0057   ::absl::log_internal::NullStreamMaybeFatal(::absl::LogSeverity::kFatal)
0058 
0059 #define ABSL_LOG_INTERNAL_CHECK(failure_message) ABSL_LOGGING_INTERNAL_LOG_FATAL
0060 #define ABSL_LOG_INTERNAL_QCHECK(failure_message) \
0061   ABSL_LOGGING_INTERNAL_LOG_QFATAL
0062 
0063 #else  // !defined(STRIP_LOG) || !STRIP_LOG
0064 
0065 #define ABSL_LOG_INTERNAL_ATTRIBUTE_UNUSED_IF_STRIP_LOG
0066 
0067 #define ABSL_LOGGING_INTERNAL_LOG_INFO \
0068   ::absl::log_internal::LogMessage(    \
0069       __FILE__, __LINE__, ::absl::log_internal::LogMessage::InfoTag{})
0070 #define ABSL_LOGGING_INTERNAL_LOG_WARNING \
0071   ::absl::log_internal::LogMessage(       \
0072       __FILE__, __LINE__, ::absl::log_internal::LogMessage::WarningTag{})
0073 #define ABSL_LOGGING_INTERNAL_LOG_ERROR \
0074   ::absl::log_internal::LogMessage(     \
0075       __FILE__, __LINE__, ::absl::log_internal::LogMessage::ErrorTag{})
0076 #define ABSL_LOGGING_INTERNAL_LOG_FATAL \
0077   ::absl::log_internal::LogMessageFatal(__FILE__, __LINE__)
0078 #define ABSL_LOGGING_INTERNAL_LOG_QFATAL \
0079   ::absl::log_internal::LogMessageQuietlyFatal(__FILE__, __LINE__)
0080 #define ABSL_LOGGING_INTERNAL_LOG_DFATAL \
0081   ::absl::log_internal::LogMessage(__FILE__, __LINE__, ::absl::kLogDebugFatal)
0082 #define ABSL_LOGGING_INTERNAL_LOG_LEVEL(severity)      \
0083   ::absl::log_internal::LogMessage(__FILE__, __LINE__, \
0084                                    absl_log_internal_severity)
0085 
0086 // Fatal `DLOG`s expand a little differently to avoid being `[[noreturn]]`.
0087 #define ABSL_LOGGING_INTERNAL_DLOG_FATAL \
0088   ::absl::log_internal::LogMessageDebugFatal(__FILE__, __LINE__)
0089 #define ABSL_LOGGING_INTERNAL_DLOG_QFATAL \
0090   ::absl::log_internal::LogMessageQuietlyDebugFatal(__FILE__, __LINE__)
0091 
0092 // These special cases dispatch to special-case constructors that allow us to
0093 // avoid an extra function call and shrink non-LTO binaries by a percent or so.
0094 #define ABSL_LOG_INTERNAL_CHECK(failure_message) \
0095   ::absl::log_internal::LogMessageFatal(__FILE__, __LINE__, failure_message)
0096 #define ABSL_LOG_INTERNAL_QCHECK(failure_message)                  \
0097   ::absl::log_internal::LogMessageQuietlyFatal(__FILE__, __LINE__, \
0098                                                failure_message)
0099 #endif  // !defined(STRIP_LOG) || !STRIP_LOG
0100 
0101 // This part of a non-fatal `DLOG`s expands the same as `LOG`.
0102 #define ABSL_LOGGING_INTERNAL_DLOG_INFO ABSL_LOGGING_INTERNAL_LOG_INFO
0103 #define ABSL_LOGGING_INTERNAL_DLOG_WARNING ABSL_LOGGING_INTERNAL_LOG_WARNING
0104 #define ABSL_LOGGING_INTERNAL_DLOG_ERROR ABSL_LOGGING_INTERNAL_LOG_ERROR
0105 #define ABSL_LOGGING_INTERNAL_DLOG_DFATAL ABSL_LOGGING_INTERNAL_LOG_DFATAL
0106 #define ABSL_LOGGING_INTERNAL_DLOG_LEVEL ABSL_LOGGING_INTERNAL_LOG_LEVEL
0107 
0108 #endif  // ABSL_LOG_INTERNAL_STRIP_H_