log_severity.h
Go to the documentation of this file.
00001 // Copyright 2017 The Abseil Authors.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //      https://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 // Unless required by applicable law or agreed to in writing, software
00010 // distributed under the License is distributed on an "AS IS" BASIS,
00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 // See the License for the specific language governing permissions and
00013 // limitations under the License.
00014 
00015 #ifndef ABSL_BASE_INTERNAL_LOG_SEVERITY_H_
00016 #define ABSL_BASE_INTERNAL_LOG_SEVERITY_H_
00017 
00018 #include <array>
00019 #include <ostream>
00020 
00021 #include "absl/base/attributes.h"
00022 
00023 namespace absl {
00024 
00025 // Four severity levels are defined.  Logging APIs should terminate the program
00026 // when a message is logged at severity `kFatal`; the other levels have no
00027 // special semantics.
00028 enum class LogSeverity : int {
00029   kInfo = 0,
00030   kWarning = 1,
00031   kError = 2,
00032   kFatal = 3,
00033 };
00034 
00035 // Returns an iterable of all standard `absl::LogSeverity` values, ordered from
00036 // least to most severe.
00037 constexpr std::array<absl::LogSeverity, 4> LogSeverities() {
00038   return {{absl::LogSeverity::kInfo, absl::LogSeverity::kWarning,
00039            absl::LogSeverity::kError, absl::LogSeverity::kFatal}};
00040 }
00041 
00042 // Returns the all-caps string representation (e.g. "INFO") of the specified
00043 // severity level if it is one of the normal levels and "UNKNOWN" otherwise.
00044 constexpr const char* LogSeverityName(absl::LogSeverity s) {
00045   return s == absl::LogSeverity::kInfo
00046              ? "INFO"
00047              : s == absl::LogSeverity::kWarning
00048                    ? "WARNING"
00049                    : s == absl::LogSeverity::kError
00050                          ? "ERROR"
00051                          : s == absl::LogSeverity::kFatal ? "FATAL" : "UNKNOWN";
00052 }
00053 
00054 // Values less than `kInfo` normalize to `kInfo`; values greater than `kFatal`
00055 // normalize to `kError` (**NOT** `kFatal`).
00056 constexpr absl::LogSeverity NormalizeLogSeverity(absl::LogSeverity s) {
00057   return s < absl::LogSeverity::kInfo
00058              ? absl::LogSeverity::kInfo
00059              : s > absl::LogSeverity::kFatal ? absl::LogSeverity::kError : s;
00060 }
00061 constexpr absl::LogSeverity NormalizeLogSeverity(int s) {
00062   return NormalizeLogSeverity(static_cast<absl::LogSeverity>(s));
00063 }
00064 
00065 // The exact representation of a streamed `absl::LogSeverity` is deliberately
00066 // unspecified; do not rely on it.
00067 std::ostream& operator<<(std::ostream& os, absl::LogSeverity s);
00068 
00069 }  // namespace absl
00070 
00071 #endif  // ABSL_BASE_INTERNAL_LOG_SEVERITY_H_


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:42:15