proxygen
TestLogHandler.cpp
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  */
17 
18 #include <folly/MapUtil.h>
19 
20 namespace folly {
21 
22 std::vector<std::string> TestLogHandler::getMessageValues() const {
23  std::vector<std::string> values;
24  values.reserve(messages_.size());
25  for (const auto& msgInfo : messages_) {
26  values.push_back(msgInfo.first.getMessage());
27  }
28  return values;
29 }
30 
31 std::shared_ptr<LogHandler> TestLogHandlerFactory::createHandler(
32  const Options& options) {
33  return std::make_shared<TestLogHandler>(LogHandlerConfig{type_, options});
34 }
35 
36 std::shared_ptr<LogHandler> TestLogHandlerFactory::updateHandler(
37  const std::shared_ptr<LogHandler>& existingHandler,
38  const Options& options) {
39  // Only re-use an existing handler in-place if it is a TestLogHandler
40  // and if the new options contain reuse_handler
41  auto existing = std::dynamic_pointer_cast<TestLogHandler>(existingHandler);
42  if (!existing || !get_ptr(options, "reuse_handler")) {
43  return createHandler(options);
44  }
45 
46  existing->setOptions(options);
47  return existing;
48 }
49 
50 } // namespace folly
const Map::mapped_type * get_ptr(const Map &map, const Key &key)
Definition: MapUtil.h:169
std::shared_ptr< LogHandler > createHandler(const Options &options) override
std::vector< std::pair< LogMessage, const LogCategory * > > messages_
std::vector< std::string > getMessageValues() const
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
std::shared_ptr< LogHandler > updateHandler(const std::shared_ptr< LogHandler > &existingHandler, const Options &options) override
Type type_
Definition: JSONSchema.cpp:208
std::unordered_map< std::string, std::string > Options
std::vector< int > values(1'000)