proxygen
Logger.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 <folly/Conv.h>
19 #include <folly/Format.h>
21 #include <folly/logging/LogLevel.h>
24 
34 #define FB_LOG(logger, level, ...) \
35  FB_LOG_IMPL( \
36  logger, \
37  ::folly::LogLevel::level, \
38  ::folly::LogStreamProcessor::APPEND, \
39  ##__VA_ARGS__)
40 
53 #define FB_LOGF(logger, level, fmt, arg1, ...) \
54  FB_LOG_IMPL( \
55  logger, \
56  ::folly::LogLevel::level, \
57  ::folly::LogStreamProcessor::FORMAT, \
58  fmt, \
59  arg1, \
60  ##__VA_ARGS__)
61 
75 #define FB_LOG_RAW(logger, level, filename, linenumber, functionName, ...) \
76  FB_LOG_RAW_IMPL( \
77  logger, \
78  level, \
79  filename, \
80  linenumber, \
81  functionName, \
82  ::folly::LogStreamProcessor::APPEND, \
83  ##__VA_ARGS__)
84 
89 #define FB_LOGF_RAW( \
90  logger, level, filename, linenumber, functionName, fmt, arg1, ...) \
91  FB_LOG_RAW_IMPL( \
92  logger, \
93  level, \
94  filename, \
95  linenumber, \
96  functionName, \
97  ::folly::LogStreamProcessor::FORMAT, \
98  fmt, \
99  arg1, \
100  ##__VA_ARGS__)
101 
107 #define FB_LOG_IMPL(logger, level, type, ...) \
108  (!(logger).getCategory()->logCheck(level)) \
109  ? ::folly::logDisabledHelper( \
110  ::folly::bool_constant<::folly::isLogLevelFatal(level)>{}) \
111  : ::folly::LogStreamVoidify<::folly::isLogLevelFatal(level)>{} & \
112  ::folly::LogStreamProcessor{(logger).getCategory(), \
113  (level), \
114  __FILE__, \
115  __LINE__, \
116  __func__, \
117  (type), \
118  ##__VA_ARGS__} \
119  .stream()
120 
130 #define FB_LOG_RAW_IMPL( \
131  logger, level, filename, line, functionName, type, ...) \
132  (!(logger).getCategory()->logCheck(level)) \
133  ? static_cast<void>(0) \
134  : ::folly::LogStreamVoidify<false>{} & \
135  ::folly::LogStreamProcessor{(logger).getCategory(), \
136  (level), \
137  (filename), \
138  (line), \
139  (functionName), \
140  (type), \
141  ##__VA_ARGS__} \
142  .stream()
143 
144 namespace folly {
145 
146 class LoggerDB;
147 class LogMessage;
148 
157 class Logger {
158  public:
165  explicit Logger(folly::StringPiece name);
166 
170  explicit Logger(LogCategory* cat);
171 
179 
184  return category_;
185  }
186 
187  private:
188  LogCategory* const category_{nullptr};
189 };
190 } // namespace folly
auto cat
Logger(folly::StringPiece name)
Definition: Logger.cpp:28
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
LogCategory *const category_
Definition: Logger.h:188
const char * name
Definition: http_parser.c:437
LogCategory * getCategory() const
Definition: Logger.h:183