proxygen
StandardLogHandler.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 <memory>
19 
20 #include <folly/File.h>
21 #include <folly/Range.h>
24 
25 namespace folly {
26 
27 class LogFormatter;
28 class LogWriter;
29 
42  public:
45  std::shared_ptr<LogFormatter> formatter,
46  std::shared_ptr<LogWriter> writer,
47  LogLevel syncLevel = LogLevel::MAX_LEVEL);
49 
53  const std::shared_ptr<LogFormatter>& getFormatter() const {
54  return formatter_;
55  }
56 
60  const std::shared_ptr<LogWriter>& getWriter() const {
61  return writer_;
62  }
63 
70  LogLevel getLevel() const {
71  return level_.load(std::memory_order_acquire);
72  }
73 
79  void setLevel(LogLevel level) {
80  return level_.store(level, std::memory_order_release);
81  }
82 
83  void handleMessage(
84  const LogMessage& message,
85  const LogCategory* handlerCategory) override;
86 
87  void flush() override;
88 
89  LogHandlerConfig getConfig() const override;
90 
91  private:
92  std::atomic<LogLevel> level_{LogLevel::NONE};
93  std::atomic<LogLevel> syncLevel_{LogLevel::MAX_LEVEL};
94 
95  // The following variables are const, and cannot be modified after the
96  // log handler is constructed. This allows us to access them without
97  // locking when handling a message. To change these values, create a new
98  // StandardLogHandler object and replace the old handler with the new one in
99  // the LoggerDB.
100 
101  const std::shared_ptr<LogFormatter> formatter_;
102  const std::shared_ptr<LogWriter> writer_;
104 };
105 } // namespace folly
LogHandlerConfig getConfig() const override
Definition: test.c:42
void handleMessage(const LogMessage &message, const LogCategory *handlerCategory) override
const std::shared_ptr< LogWriter > writer_
const LogHandlerConfig config_
std::atomic< LogLevel > syncLevel_
const std::shared_ptr< LogFormatter > & getFormatter() const
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
const std::shared_ptr< LogFormatter > formatter_
StandardLogHandler(LogHandlerConfig config, std::shared_ptr< LogFormatter > formatter, std::shared_ptr< LogWriter > writer, LogLevel syncLevel=LogLevel::MAX_LEVEL)
AHArrayT::Config config
std::atomic< LogLevel > level_
void setLevel(LogLevel level)
LogLevel
Definition: LogLevel.h:38
const std::shared_ptr< LogWriter > & getWriter() const