proxygen
ConfigHelpers.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2004-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 <ostream>
19 
20 #include <folly/String.h>
24 
25 namespace folly {
26 
27 std::ostream& operator<<(std::ostream& os, const LogConfig& config) {
28  // We could just use folly::toPrettyJson(logConfigToDynamic(config))
29  // However, the format here is much more compact and easier to read if there
30  // are discrepancies between configs in a test check.
31 
32  // Sort the categories by name before printing
33  os << "{\n categories: {\n";
34  std::vector<std::string> names;
35  const auto& catConfigs = config.getCategoryConfigs();
36  for (const auto& cc : catConfigs) {
37  names.push_back(cc.first);
38  }
39  std::sort(names.begin(), names.end());
40  for (const auto& name : names) {
41  os << " " << name << "=" << catConfigs.at(name) << "\n";
42  }
43 
44  // Sort the handlers by name before printing
45  os << " }\n handlers: {\n";
46  const auto& handlerConfigs = config.getHandlerConfigs();
47  names.clear();
48  for (const auto& cc : handlerConfigs) {
49  names.push_back(cc.first);
50  }
51  std::sort(names.begin(), names.end());
52  for (const auto& name : names) {
53  os << " " << name << "=" << handlerConfigs.at(name) << "\n";
54  }
55 
56  os << " }\n}";
57  return os;
58 }
59 
60 std::ostream& operator<<(std::ostream& os, const LogCategoryConfig& config) {
61  // Rather than printing the JSON configuration, we print a shorter
62  // representation closer to the basic config string format.
63  os << logLevelToString(config.level);
64  if (!config.inheritParentLevel) {
65  os << "!";
66  }
67  if (config.handlers.hasValue()) {
68  os << ":" << join(",", config.handlers.value());
69  }
70  return os;
71 }
72 
73 std::ostream& operator<<(std::ostream& os, const LogHandlerConfig& config) {
74  // Rather than printing the JSON configuration, we print a shorter
75  // representation closer to the basic config string format.
76  os << (config.type ? config.type.value() : "[no type]");
77  bool first = true;
78  for (const auto& opt : config.options) {
79  if (!first) {
80  os << ",";
81  } else {
82  os << ":";
83  first = false;
84  }
85  os << opt.first << "=" << opt.second;
86  }
87  return os;
88 }
89 
90 void PrintTo(const std::shared_ptr<LogHandler>& handler, std::ostream* os) {
91  *os << "Handler(" << handler->getConfig() << ")";
92 }
93 
94 } // namespace folly
const CategoryConfigMap & getCategoryConfigs() const
Definition: LogConfig.h:45
Optional< std::vector< std::string > > handlers
void PrintTo(const dynamic &dyn, std::ostream *os)
Definition: json.cpp:937
The non test part of the code is expected to have failures gtest_output_test_ cc
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
Optional< std::string > type
string logLevelToString(LogLevel level)
Definition: LogLevel.cpp:109
AHArrayT::Config config
void handler(int, siginfo_t *, void *)
const char * name
Definition: http_parser.c:437
FOLLY_CPP14_CONSTEXPR bool hasValue() const noexcept
Definition: Optional.h:300
const HandlerConfigMap & getHandlerConfigs() const
Definition: LogConfig.h:48
void join(const Delim &delimiter, Iterator begin, Iterator end, String &output)
Definition: String-inl.h:498
FOLLY_CPP14_CONSTEXPR const Value & value() const &
Definition: Optional.h:268
constexpr detail::First first
Definition: Base-inl.h:2553
std::ostream & operator<<(std::ostream &out, dynamic const &d)
Definition: dynamic-inl.h:1158