summaryrefslogtreecommitdiff
path: root/absl/base
diff options
context:
space:
mode:
authorGravatar Andy Getzendanner <durandal@google.com>2023-12-05 14:00:19 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2023-12-05 14:01:11 -0800
commit3e6ecec7d3c9c504c9951b34230b22527758e0cd (patch)
tree66443d2b0f554d0fbe24a0b15c2c968bab4f32e5 /absl/base
parent71d553b12397ef81e9111b4fa21c68af3c0bf8b9 (diff)
Roll-forward: Honor ABSL_MIN_LOG_LEVEL in CHECK_XX, CHECK_STRXX, CHECK_OK, and the QCHECK flavors of these.
In particular, if ABSL_MIN_LOG_LEVEL exceeds kFatal, these should, upon failure, terminate the program without logging anything. The lack of logging should be visible to the optimizer so that it can strip string literals and stringified variable names from the object file. Making some edge cases work under Clang required rewriting NormalizeLogSeverity to help make constraints on its return value more obvious to the optimizer. PiperOrigin-RevId: 588181755 Change-Id: I95db3bae39f8dadb52a307ca3b80775db23de766
Diffstat (limited to 'absl/base')
-rw-r--r--absl/base/log_severity.h21
1 files changed, 11 insertions, 10 deletions
diff --git a/absl/base/log_severity.h b/absl/base/log_severity.h
index c8bcd2fd..d0795a2d 100644
--- a/absl/base/log_severity.h
+++ b/absl/base/log_severity.h
@@ -99,13 +99,13 @@ static constexpr absl::LogSeverity kLogDebugFatal = absl::LogSeverity::kFatal;
// Returns the all-caps string representation (e.g. "INFO") of the specified
// severity level if it is one of the standard levels and "UNKNOWN" otherwise.
constexpr const char* LogSeverityName(absl::LogSeverity s) {
- return s == absl::LogSeverity::kInfo
- ? "INFO"
- : s == absl::LogSeverity::kWarning
- ? "WARNING"
- : s == absl::LogSeverity::kError
- ? "ERROR"
- : s == absl::LogSeverity::kFatal ? "FATAL" : "UNKNOWN";
+ switch (s) {
+ case absl::LogSeverity::kInfo: return "INFO";
+ case absl::LogSeverity::kWarning: return "WARNING";
+ case absl::LogSeverity::kError: return "ERROR";
+ case absl::LogSeverity::kFatal: return "FATAL";
+ default: return "UNKNOWN";
+ }
}
// NormalizeLogSeverity()
@@ -113,9 +113,10 @@ constexpr const char* LogSeverityName(absl::LogSeverity s) {
// Values less than `kInfo` normalize to `kInfo`; values greater than `kFatal`
// normalize to `kError` (**NOT** `kFatal`).
constexpr absl::LogSeverity NormalizeLogSeverity(absl::LogSeverity s) {
- return s < absl::LogSeverity::kInfo
- ? absl::LogSeverity::kInfo
- : s > absl::LogSeverity::kFatal ? absl::LogSeverity::kError : s;
+ absl::LogSeverity n = s;
+ if (n < absl::LogSeverity::kInfo) n = absl::LogSeverity::kInfo;
+ if (n > absl::LogSeverity::kFatal) n = absl::LogSeverity::kError;
+ return n;
}
constexpr absl::LogSeverity NormalizeLogSeverity(int s) {
return absl::NormalizeLogSeverity(static_cast<absl::LogSeverity>(s));