proxygen
LogLevel.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include <cstdint>
19 #include <iosfwd>
20 #include <string>
21 #include <type_traits>
22 
23 #include <folly/Portability.h>
24 #include <folly/Range.h>
25 
26 namespace folly {
27 
38 enum class LogLevel : uint32_t {
39  UNINITIALIZED = 0,
40  NONE = 1,
41  MIN_LEVEL = 1,
42 
43  // "DBG" is the lowest (aka most verbose) debug log level.
44  // This level is intended to be primarily used in log category settings.
45  // In your code it is usually better to use one of the finer-grained DBGn
46  // levels. In your log category settings you can then set the log category
47  // level to a specific DBGn level, or to to main DBG level to enable all DBGn
48  // messages.
49  //
50  // This is named "DBG" rather than "DEBUG" since some open source projects
51  // define "DEBUG" as a preprocessor macro.
52  DBG = 1000,
53 
54  // Fine-grained debug log levels.
55  DBG0 = 1999,
56  DBG1 = 1998,
57  DBG2 = 1997,
58  DBG3 = 1996,
59  DBG4 = 1995,
60  DBG5 = 1994,
61  DBG6 = 1993,
62  DBG7 = 1992,
63  DBG8 = 1991,
64  DBG9 = 1990,
65 
66  INFO = 2000,
67  // Fine-grained info log levels.
68  INFO0 = 2999,
69  INFO1 = 2998,
70  INFO2 = 2997,
71  INFO3 = 2996,
72  INFO4 = 2995,
73  INFO5 = 2994,
74  INFO6 = 2993,
75  INFO7 = 2992,
76  INFO8 = 2991,
77  INFO9 = 2990,
78 
79  WARN = 3000,
80  WARNING = 3000,
81 
82  // Unfortunately Windows headers #define ERROR, so we cannot use
83  // it as an enum value name. We only provide ERR instead.
84  ERR = 4000,
85 
86  CRITICAL = 5000,
87 
88  // DFATAL log messages crash the program on debug builds.
89  DFATAL = 0x7ffffffe,
90  // FATAL log messages always abort the program.
91  // This level is equivalent to MAX_LEVEL.
92  FATAL = 0x7fffffff,
93 
94  // The most significant bit is used by LogCategory to store a flag value,
95  // so the maximum value has that bit cleared.
96  //
97  // (We call this MAX_LEVEL instead of MAX just since MAX() is commonly
98  // defined as a preprocessor macro by some C headers.)
99  MAX_LEVEL = 0x7fffffff,
100 };
101 
103 
104 /*
105  * Support adding and subtracting integers from LogLevels, to create slightly
106  * adjusted log level values.
107  */
108 inline constexpr LogLevel operator+(LogLevel level, uint32_t value) {
109  // Cap the result at LogLevel::MAX_LEVEL
110  return ((static_cast<uint32_t>(level) + value) >
111  static_cast<uint32_t>(LogLevel::MAX_LEVEL))
113  : static_cast<LogLevel>(static_cast<uint32_t>(level) + value);
114 }
116  level = level + value;
117  return level;
118 }
119 inline constexpr LogLevel operator-(LogLevel level, uint32_t value) {
120  return static_cast<LogLevel>(static_cast<uint32_t>(level) - value);
121 }
123  level = level - value;
124  return level;
125 }
126 
131 
136 
140 std::ostream& operator<<(std::ostream& os, LogLevel level);
141 
145 inline constexpr bool isLogLevelFatal(LogLevel level) {
146  return folly::kIsDebug ? (level >= LogLevel::DFATAL)
147  : (level >= LogLevel::FATAL);
148 }
149 } // namespace folly
constexpr auto kIsDebug
Definition: Portability.h:264
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
LogLevel stringToLogLevel(StringPiece name)
Definition: LogLevel.cpp:42
string logLevelToString(LogLevel level)
Definition: LogLevel.cpp:109
const char * name
Definition: http_parser.c:437
constexpr LogLevel kDefaultLogLevel
Definition: LogLevel.h:102
LogLevel & operator-=(LogLevel &level, uint32_t value)
Definition: LogLevel.h:122
LogLevel
Definition: LogLevel.h:38
const char * string
Definition: Conv.cpp:212
basic_fbstring< E, T, A, S > operator+(const basic_fbstring< E, T, A, S > &lhs, const basic_fbstring< E, T, A, S > &rhs)
Definition: FBString.h:2447
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
constexpr LogLevel operator-(LogLevel level, uint32_t value)
Definition: LogLevel.h:119
constexpr bool isLogLevelFatal(LogLevel level)
Definition: LogLevel.h:145
LogLevel & operator+=(LogLevel &level, uint32_t value)
Definition: LogLevel.h:115
std::ostream & operator<<(std::ostream &out, dynamic const &d)
Definition: dynamic-inl.h:1158