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(log_internal_severity) 41 #define ABSL_LOG_INTERNAL_CHECK(failure_message) ABSL_LOGGING_INTERNAL_LOG_FATAL 42 #define ABSL_LOG_INTERNAL_QCHECK(failure_message) \ 43 ABSL_LOGGING_INTERNAL_LOG_QFATAL 44 #else // !defined(STRIP_LOG) || !STRIP_LOG 45 #define ABSL_LOGGING_INTERNAL_LOG_INFO \ 46 ::absl::log_internal::LogMessage(__FILE__, __LINE__, \ 47 ::absl::LogSeverity::kInfo) 48 #define ABSL_LOGGING_INTERNAL_LOG_WARNING \ 49 ::absl::log_internal::LogMessage(__FILE__, __LINE__, \ 50 ::absl::LogSeverity::kWarning) 51 #define ABSL_LOGGING_INTERNAL_LOG_ERROR \ 52 ::absl::log_internal::LogMessage(__FILE__, __LINE__, \ 53 ::absl::LogSeverity::kError) 54 #define ABSL_LOGGING_INTERNAL_LOG_FATAL \ 55 ::absl::log_internal::LogMessageFatal(__FILE__, __LINE__) 56 #define ABSL_LOGGING_INTERNAL_LOG_QFATAL \ 57 ::absl::log_internal::LogMessageQuietlyFatal(__FILE__, __LINE__) 58 #define ABSL_LOGGING_INTERNAL_LOG_DFATAL \ 59 ::absl::log_internal::LogMessage(__FILE__, __LINE__, ::absl::kLogDebugFatal) 60 #define ABSL_LOGGING_INTERNAL_LOG_LEVEL(severity) \ 61 ::absl::log_internal::LogMessage(__FILE__, __LINE__, log_internal_severity) 62 // These special cases dispatch to special-case constructors that allow us to 63 // avoid an extra function call and shrink non-LTO binaries by a percent or so. 64 #define ABSL_LOG_INTERNAL_CHECK(failure_message) \ 65 ::absl::log_internal::LogMessageFatal(__FILE__, __LINE__, failure_message) 66 #define ABSL_LOG_INTERNAL_QCHECK(failure_message) \ 67 ::absl::log_internal::LogMessageQuietlyFatal(__FILE__, __LINE__, \ 68 failure_message) 69 #endif // !defined(STRIP_LOG) || !STRIP_LOG 70 71 #endif // ABSL_LOG_INTERNAL_STRIP_H_ 72