diff options
author | Abseil Team <absl-team@google.com> | 2021-12-20 08:44:32 -0800 |
---|---|---|
committer | Gennadiy Rozental <rogeeff@google.com> | 2021-12-20 19:17:38 +0000 |
commit | f523d0dd69806d8057a898bb2595910558156aaa (patch) | |
tree | d9d11b6417c37ad1e83627e89010c2b7fed51a67 /absl/base/log_severity.h | |
parent | 52d41a9ec23e39db7e2cbce5c9449506cf2d3a5c (diff) |
Export of internal Abseil changes
--
1e25fb5996193524bf2f75781f1e6bdcdf972a3a by Gennadiy Rozental <rogeeff@google.com>:
Introduce enums to represent lower and upper thresholds for LogSeverity.
PiperOrigin-RevId: 417414673
--
abfddb3a6ad8ce4849fbb6dadb34d7d6295def0f by Abseil Team <absl-team@google.com>:
Restore __arch64__ macro check for SPARC
PiperOrigin-RevId: 416798208
PiperOrigin-RevId: 416688543
GitOrigin-RevId: 1e25fb5996193524bf2f75781f1e6bdcdf972a3a
Change-Id: I424dd98e5e07420d5f9dfd191f2bfc06036e2bd1
Diffstat (limited to 'absl/base/log_severity.h')
-rw-r--r-- | absl/base/log_severity.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/absl/base/log_severity.h b/absl/base/log_severity.h index 22364224..8bdca38b 100644 --- a/absl/base/log_severity.h +++ b/absl/base/log_severity.h @@ -115,6 +115,57 @@ constexpr absl::LogSeverity NormalizeLogSeverity(int s) { // unspecified; do not rely on it. std::ostream& operator<<(std::ostream& os, absl::LogSeverity s); +// Enums representing a lower bound for LogSeverity. APIs that only operate on +// messages of at least a certain level (for example, `SetMinLogLevel()`) use +// this type to specify that level. absl::LogSeverityAtLeast::kInfinity is +// a level above all threshold levels and therefore no log message will +// ever meet this threshold. +enum class LogSeverityAtLeast : int { + kInfo = static_cast<int>(absl::LogSeverity::kInfo), + kWarning = static_cast<int>(absl::LogSeverity::kWarning), + kError = static_cast<int>(absl::LogSeverity::kError), + kFatal = static_cast<int>(absl::LogSeverity::kFatal), + kInfinity = 1000, +}; + +std::ostream& operator<<(std::ostream& os, absl::LogSeverityAtLeast s); + +// Enums representing an upper bound for LogSeverity. APIs that only operate on +// messages of at most a certain level (for example, buffer all messages at or +// below a certain level) use this type to specify that level. +// absl::LogSeverityAtMost::kNegativeInfinity is a level below all threshold +// levels and therefore will exclude all log messages. +enum class LogSeverityAtMost : int { + kNegativeInfinity = -1000, + kInfo = static_cast<int>(absl::LogSeverity::kInfo), + kWarning = static_cast<int>(absl::LogSeverity::kWarning), + kError = static_cast<int>(absl::LogSeverity::kError), + kFatal = static_cast<int>(absl::LogSeverity::kFatal), +}; + +std::ostream& operator<<(std::ostream& os, absl::LogSeverityAtMost s); + +#define COMPOP(op1, op2, T) \ + constexpr bool operator op1(absl::T lhs, absl::LogSeverity rhs) { \ + return static_cast<absl::LogSeverity>(lhs) op1 rhs; \ + } \ + constexpr bool operator op2(absl::LogSeverity lhs, absl::T rhs) { \ + return lhs op2 static_cast<absl::LogSeverity>(rhs); \ + } + +// Comparisons between `LogSeverity` and `LogSeverityAtLeast`/ +// `LogSeverityAtMost` are only supported in one direction. +// Valid checks are: +// LogSeverity >= LogSeverityAtLeast +// LogSeverity < LogSeverityAtLeast +// LogSeverity <= LogSeverityAtMost +// LogSeverity > LogSeverityAtMost +COMPOP(>, <, LogSeverityAtLeast) +COMPOP(<=, >=, LogSeverityAtLeast) +COMPOP(<, >, LogSeverityAtMost) +COMPOP(>=, <=, LogSeverityAtMost) +#undef COMPOP + ABSL_NAMESPACE_END } // namespace absl |