strip.h (4957B)
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 // SKIP_ABSL_INLINE_NAMESPACE_CHECK 20 21 #ifndef ABSL_LOG_INTERNAL_STRIP_H_ 22 #define ABSL_LOG_INTERNAL_STRIP_H_ 23 24 #include "absl/base/attributes.h" // IWYU pragma: keep 25 #include "absl/base/log_severity.h" 26 #include "absl/log/internal/log_message.h" 27 #include "absl/log/internal/nullstream.h" 28 29 // `ABSL_LOGGING_INTERNAL_LOG_*` evaluates to a temporary `LogMessage` object or 30 // to a related object with a compatible API but different behavior. This set 31 // of defines comes in three flavors: vanilla, plus two variants that strip some 32 // logging in subtly different ways for subtly different reasons (see below). 33 #if defined(STRIP_LOG) && STRIP_LOG 34 35 #define ABSL_LOGGING_INTERNAL_LOG_INFO ::absl::log_internal::NullStream() 36 #define ABSL_LOGGING_INTERNAL_LOG_WARNING ::absl::log_internal::NullStream() 37 #define ABSL_LOGGING_INTERNAL_LOG_ERROR ::absl::log_internal::NullStream() 38 #define ABSL_LOGGING_INTERNAL_LOG_FATAL ::absl::log_internal::NullStreamFatal() 39 #define ABSL_LOGGING_INTERNAL_LOG_QFATAL ::absl::log_internal::NullStreamFatal() 40 #define ABSL_LOGGING_INTERNAL_LOG_DFATAL \ 41 ::absl::log_internal::NullStreamMaybeFatal(::absl::kLogDebugFatal) 42 #define ABSL_LOGGING_INTERNAL_LOG_LEVEL(severity) \ 43 ::absl::log_internal::NullStreamMaybeFatal(absl_log_internal_severity) 44 45 // Fatal `DLOG`s expand a little differently to avoid being `[[noreturn]]`. 46 #define ABSL_LOGGING_INTERNAL_DLOG_FATAL \ 47 ::absl::log_internal::NullStreamMaybeFatal(::absl::LogSeverity::kFatal) 48 #define ABSL_LOGGING_INTERNAL_DLOG_QFATAL \ 49 ::absl::log_internal::NullStreamMaybeFatal(::absl::LogSeverity::kFatal) 50 51 #define ABSL_LOG_INTERNAL_CHECK(failure_message) ABSL_LOGGING_INTERNAL_LOG_FATAL 52 #define ABSL_LOG_INTERNAL_QCHECK(failure_message) \ 53 ABSL_LOGGING_INTERNAL_LOG_QFATAL 54 55 #else // !defined(STRIP_LOG) || !STRIP_LOG 56 57 #define ABSL_LOGGING_INTERNAL_LOG_INFO \ 58 ::absl::log_internal::LogMessage( \ 59 __FILE__, __LINE__, ::absl::log_internal::LogMessage::InfoTag{}) 60 #define ABSL_LOGGING_INTERNAL_LOG_WARNING \ 61 ::absl::log_internal::LogMessage( \ 62 __FILE__, __LINE__, ::absl::log_internal::LogMessage::WarningTag{}) 63 #define ABSL_LOGGING_INTERNAL_LOG_ERROR \ 64 ::absl::log_internal::LogMessage( \ 65 __FILE__, __LINE__, ::absl::log_internal::LogMessage::ErrorTag{}) 66 #define ABSL_LOGGING_INTERNAL_LOG_FATAL \ 67 ::absl::log_internal::LogMessageFatal(__FILE__, __LINE__) 68 #define ABSL_LOGGING_INTERNAL_LOG_QFATAL \ 69 ::absl::log_internal::LogMessageQuietlyFatal(__FILE__, __LINE__) 70 #define ABSL_LOGGING_INTERNAL_LOG_DFATAL \ 71 ::absl::log_internal::LogMessage(__FILE__, __LINE__, ::absl::kLogDebugFatal) 72 #define ABSL_LOGGING_INTERNAL_LOG_LEVEL(severity) \ 73 ::absl::log_internal::LogMessage(__FILE__, __LINE__, \ 74 absl_log_internal_severity) 75 76 // Fatal `DLOG`s expand a little differently to avoid being `[[noreturn]]`. 77 #define ABSL_LOGGING_INTERNAL_DLOG_FATAL \ 78 ::absl::log_internal::LogMessageDebugFatal(__FILE__, __LINE__) 79 #define ABSL_LOGGING_INTERNAL_DLOG_QFATAL \ 80 ::absl::log_internal::LogMessageQuietlyDebugFatal(__FILE__, __LINE__) 81 82 // These special cases dispatch to special-case constructors that allow us to 83 // avoid an extra function call and shrink non-LTO binaries by a percent or so. 84 #define ABSL_LOG_INTERNAL_CHECK(failure_message) \ 85 ::absl::log_internal::LogMessageFatal(__FILE__, __LINE__, failure_message) 86 #define ABSL_LOG_INTERNAL_QCHECK(failure_message) \ 87 ::absl::log_internal::LogMessageQuietlyFatal(__FILE__, __LINE__, \ 88 failure_message) 89 #endif // !defined(STRIP_LOG) || !STRIP_LOG 90 91 // This part of a non-fatal `DLOG`s expands the same as `LOG`. 92 #define ABSL_LOGGING_INTERNAL_DLOG_INFO ABSL_LOGGING_INTERNAL_LOG_INFO 93 #define ABSL_LOGGING_INTERNAL_DLOG_WARNING ABSL_LOGGING_INTERNAL_LOG_WARNING 94 #define ABSL_LOGGING_INTERNAL_DLOG_ERROR ABSL_LOGGING_INTERNAL_LOG_ERROR 95 #define ABSL_LOGGING_INTERNAL_DLOG_DFATAL ABSL_LOGGING_INTERNAL_LOG_DFATAL 96 #define ABSL_LOGGING_INTERNAL_DLOG_LEVEL ABSL_LOGGING_INTERNAL_LOG_LEVEL 97 98 #define ABSL_LOGGING_INTERNAL_LOG_DO_NOT_SUBMIT ABSL_LOGGING_INTERNAL_LOG_ERROR 99 100 #endif // ABSL_LOG_INTERNAL_STRIP_H_