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