proxygen
TestLogHandler.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 <map>
19 #include <string>
20 #include <utility>
21 #include <vector>
22 
27 
28 namespace folly {
29 
36 class TestLogHandler : public LogHandler {
37  public:
39 
40  TestLogHandler() : config_{"test"} {}
42  : config_{std::move(config)} {}
43 
44  std::vector<std::pair<LogMessage, const LogCategory*>>& getMessages() {
45  return messages_;
46  }
47 
48  std::vector<std::string> getMessageValues() const;
49  void clearMessages() {
50  messages_.clear();
51  }
52 
54  const LogMessage& message,
55  const LogCategory* handlerCategory) override {
56  messages_.emplace_back(message, handlerCategory);
57  }
58 
59  void flush() override {
60  ++flushCount_;
61  }
62 
64  return flushCount_;
65  }
66 
67  LogHandlerConfig getConfig() const override {
68  return config_;
69  }
70 
71  void setOptions(const Options& options) {
72  config_.options = options;
73  }
74 
75  protected:
76  std::vector<std::pair<LogMessage, const LogCategory*>> messages_;
78  std::map<std::string, std::string> options_;
80 };
81 
86  public:
88 
89  StringPiece getType() const override {
90  return type_;
91  }
92 
93  std::shared_ptr<LogHandler> createHandler(const Options& options) override;
94 
95  std::shared_ptr<LogHandler> updateHandler(
96  const std::shared_ptr<LogHandler>& existingHandler,
97  const Options& options) override;
98 
99  private:
101 };
102 
103 } // namespace folly
Definition: test.c:42
std::vector< std::pair< LogMessage, const LogCategory * > > messages_
std::string str() const
Definition: Range.h:591
std::vector< std::string > getMessageValues() const
void flush() override
TestLogHandlerFactory(StringPiece type)
std::map< std::string, std::string > options_
PskType type
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void handleMessage(const LogMessage &message, const LogCategory *handlerCategory) override
LogHandlerConfig config_
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
std::unordered_map< std::string, std::string > Options
AHArrayT::Config config
LogHandlerConfig::Options Options
uint64_t getFlushCount() const
std::vector< std::pair< LogMessage, const LogCategory * > > & getMessages()
Type type_
Definition: JSONSchema.cpp:208
void setOptions(const Options &options)
StringPiece getType() const override
const char * string
Definition: Conv.cpp:212
TestLogHandler(LogHandlerConfig config)
LogHandlerConfig getConfig() const override
std::unordered_map< std::string, std::string > Options