log_severity.h
Go to the documentation of this file.
1 // Copyright 2017 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 #ifndef ABSL_BASE_INTERNAL_LOG_SEVERITY_H_
16 #define ABSL_BASE_INTERNAL_LOG_SEVERITY_H_
17 
18 #include <array>
19 #include <ostream>
20 
21 #include "absl/base/attributes.h"
22 
23 namespace absl {
24 
25 // Four severity levels are defined. Logging APIs should terminate the program
26 // when a message is logged at severity `kFatal`; the other levels have no
27 // special semantics.
28 enum class LogSeverity : int {
29  kInfo = 0,
30  kWarning = 1,
31  kError = 2,
32  kFatal = 3,
33 };
34 
35 // Returns an iterable of all standard `absl::LogSeverity` values, ordered from
36 // least to most severe.
37 constexpr std::array<absl::LogSeverity, 4> LogSeverities() {
40 }
41 
42 // Returns the all-caps string representation (e.g. "INFO") of the specified
43 // severity level if it is one of the normal levels and "UNKNOWN" otherwise.
44 constexpr const char* LogSeverityName(absl::LogSeverity s) {
45  return s == absl::LogSeverity::kInfo
46  ? "INFO"
48  ? "WARNING"
50  ? "ERROR"
51  : s == absl::LogSeverity::kFatal ? "FATAL" : "UNKNOWN";
52 }
53 
54 // Values less than `kInfo` normalize to `kInfo`; values greater than `kFatal`
55 // normalize to `kError` (**NOT** `kFatal`).
57  return s < absl::LogSeverity::kInfo
60 }
62  return NormalizeLogSeverity(static_cast<absl::LogSeverity>(s));
63 }
64 
65 // The exact representation of a streamed `absl::LogSeverity` is deliberately
66 // unspecified; do not rely on it.
67 std::ostream& operator<<(std::ostream& os, absl::LogSeverity s);
68 
69 } // namespace absl
70 
71 #endif // ABSL_BASE_INTERNAL_LOG_SEVERITY_H_
constexpr std::array< absl::LogSeverity, 4 > LogSeverities()
Definition: log_severity.h:37
LogSeverity
Definition: log_severity.h:28
std::ostream & operator<<(std::ostream &os, absl::LogSeverity s)
Definition: log_severity.cc:21
constexpr absl::LogSeverity NormalizeLogSeverity(absl::LogSeverity s)
Definition: log_severity.h:56
Definition: algorithm.h:29
constexpr const char * LogSeverityName(absl::LogSeverity s)
Definition: log_severity.h:44


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