| 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 | #define ABSL_LOGGING_INTERNAL_LOG_INFO ::absl::log_internal::NullStream() |
| 35 | #define ABSL_LOGGING_INTERNAL_LOG_WARNING ::absl::log_internal::NullStream() |
| 36 | #define ABSL_LOGGING_INTERNAL_LOG_ERROR ::absl::log_internal::NullStream() |
| 37 | #define ABSL_LOGGING_INTERNAL_LOG_FATAL ::absl::log_internal::NullStreamFatal() |
| 38 | #define ABSL_LOGGING_INTERNAL_LOG_QFATAL ::absl::log_internal::NullStreamFatal() |
| 39 | #define ABSL_LOGGING_INTERNAL_LOG_DFATAL \ |
| 40 | ::absl::log_internal::NullStreamMaybeFatal(::absl::kLogDebugFatal) |
| 41 | #define ABSL_LOGGING_INTERNAL_LOG_LEVEL(severity) \ |
| 42 | ::absl::log_internal::NullStreamMaybeFatal(absl_log_internal_severity) |
| 43 | |
| 44 | // Fatal `DLOG`s expand a little differently to avoid being `[[noreturn]]`. |
| 45 | #define ABSL_LOGGING_INTERNAL_DLOG_FATAL \ |
| 46 | ::absl::log_internal::NullStreamMaybeFatal(::absl::LogSeverity::kFatal) |
| 47 | #define ABSL_LOGGING_INTERNAL_DLOG_QFATAL \ |
| 48 | ::absl::log_internal::NullStreamMaybeFatal(::absl::LogSeverity::kFatal) |
| 49 | |
| 50 | #define ABSL_LOG_INTERNAL_CHECK(failure_message) ABSL_LOGGING_INTERNAL_LOG_FATAL |
| 51 | #define ABSL_LOG_INTERNAL_QCHECK(failure_message) \ |
| 52 | ABSL_LOGGING_INTERNAL_LOG_QFATAL |
| 53 | |
| 54 | #else // !defined(STRIP_LOG) || !STRIP_LOG |
| 55 | |
| 56 | #define ABSL_LOGGING_INTERNAL_LOG_INFO \ |
| 57 | ::absl::log_internal::LogMessage( \ |
| 58 | __FILE__, __LINE__, ::absl::log_internal::LogMessage::InfoTag{}) |
| 59 | #define ABSL_LOGGING_INTERNAL_LOG_WARNING \ |
| 60 | ::absl::log_internal::LogMessage( \ |
| 61 | __FILE__, __LINE__, ::absl::log_internal::LogMessage::WarningTag{}) |
| 62 | #define ABSL_LOGGING_INTERNAL_LOG_ERROR \ |
| 63 | ::absl::log_internal::LogMessage( \ |
| 64 | __FILE__, __LINE__, ::absl::log_internal::LogMessage::ErrorTag{}) |
| 65 | #define ABSL_LOGGING_INTERNAL_LOG_FATAL \ |
| 66 | ::absl::log_internal::LogMessageFatal(__FILE__, __LINE__) |
| 67 | #define ABSL_LOGGING_INTERNAL_LOG_QFATAL \ |
| 68 | ::absl::log_internal::LogMessageQuietlyFatal(__FILE__, __LINE__) |
| 69 | #define ABSL_LOGGING_INTERNAL_LOG_DFATAL \ |
| 70 | ::absl::log_internal::LogMessage(__FILE__, __LINE__, ::absl::kLogDebugFatal) |
| 71 | #define ABSL_LOGGING_INTERNAL_LOG_LEVEL(severity) \ |
| 72 | ::absl::log_internal::LogMessage(__FILE__, __LINE__, \ |
| 73 | absl_log_internal_severity) |
| 74 | |
| 75 | // Fatal `DLOG`s expand a little differently to avoid being `[[noreturn]]`. |
| 76 | #define ABSL_LOGGING_INTERNAL_DLOG_FATAL \ |
| 77 | ::absl::log_internal::LogMessageDebugFatal(__FILE__, __LINE__) |
| 78 | #define ABSL_LOGGING_INTERNAL_DLOG_QFATAL \ |
| 79 | ::absl::log_internal::LogMessageQuietlyDebugFatal(__FILE__, __LINE__) |
| 80 | |
| 81 | // These special cases dispatch to special-case constructors that allow us to |
| 82 | // avoid an extra function call and shrink non-LTO binaries by a percent or so. |
| 83 | #define ABSL_LOG_INTERNAL_CHECK(failure_message) \ |
| 84 | ::absl::log_internal::LogMessageFatal(__FILE__, __LINE__, failure_message) |
| 85 | #define ABSL_LOG_INTERNAL_QCHECK(failure_message) \ |
| 86 | ::absl::log_internal::LogMessageQuietlyFatal(__FILE__, __LINE__, \ |
| 87 | failure_message) |
| 88 | #endif // !defined(STRIP_LOG) || !STRIP_LOG |
| 89 | |
| 90 | // This part of a non-fatal `DLOG`s expands the same as `LOG`. |
| 91 | #define ABSL_LOGGING_INTERNAL_DLOG_INFO ABSL_LOGGING_INTERNAL_LOG_INFO |
| 92 | #define ABSL_LOGGING_INTERNAL_DLOG_WARNING ABSL_LOGGING_INTERNAL_LOG_WARNING |
| 93 | #define ABSL_LOGGING_INTERNAL_DLOG_ERROR ABSL_LOGGING_INTERNAL_LOG_ERROR |
| 94 | #define ABSL_LOGGING_INTERNAL_DLOG_DFATAL ABSL_LOGGING_INTERNAL_LOG_DFATAL |
| 95 | #define ABSL_LOGGING_INTERNAL_DLOG_LEVEL ABSL_LOGGING_INTERNAL_LOG_LEVEL |
| 96 | |
| 97 | #endif // ABSL_LOG_INTERNAL_STRIP_H_ |
| 98 | |