proxygen
folly::LogConfig Class Reference

#include <LogConfig.h>

Public Types

using CategoryConfigMap = std::unordered_map< std::string, LogCategoryConfig >
 
using HandlerConfigMap = std::unordered_map< std::string, LogHandlerConfig >
 

Public Member Functions

 LogConfig ()=default
 
 LogConfig (HandlerConfigMap handlerConfigs, CategoryConfigMap catConfigs)
 
const CategoryConfigMapgetCategoryConfigs () const
 
const HandlerConfigMapgetHandlerConfigs () const
 
bool operator== (const LogConfig &other) const
 
bool operator!= (const LogConfig &other) const
 
void update (const LogConfig &other)
 

Private Attributes

HandlerConfigMap handlerConfigs_
 
CategoryConfigMap categoryConfigs_
 

Detailed Description

LogConfig contains configuration for the LoggerDB.

This includes information about the log levels for log categories, as well as what log handlers are configured and which categories they are attached to.

Definition at line 33 of file LogConfig.h.

Member Typedef Documentation

Definition at line 35 of file LogConfig.h.

Definition at line 36 of file LogConfig.h.

Constructor & Destructor Documentation

folly::LogConfig::LogConfig ( )
default
folly::LogConfig::LogConfig ( HandlerConfigMap  handlerConfigs,
CategoryConfigMap  catConfigs 
)
inlineexplicit

Definition at line 39 of file LogConfig.h.

References categoryConfigs_, and folly::gen::move.

42  : handlerConfigs_{std::move(handlerConfigs)},
43  categoryConfigs_{std::move(catConfigs)} {}
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
CategoryConfigMap categoryConfigs_
Definition: LogConfig.h:86
HandlerConfigMap handlerConfigs_
Definition: LogConfig.h:85

Member Function Documentation

const CategoryConfigMap& folly::LogConfig::getCategoryConfigs ( ) const
inline
const HandlerConfigMap& folly::LogConfig::getHandlerConfigs ( ) const
inline

Definition at line 48 of file LogConfig.h.

References handlerConfigs_, operator!=(), operator==(), and update().

Referenced by folly::logConfigToDynamic(), folly::operator<<(), and folly::LoggerDB::startConfigUpdate().

48  {
49  return handlerConfigs_;
50  }
HandlerConfigMap handlerConfigs_
Definition: LogConfig.h:85
bool folly::LogConfig::operator!= ( const LogConfig other) const

Definition at line 27 of file LogConfig.cpp.

Referenced by getHandlerConfigs().

27  {
28  return !(*this == other);
29 }
bool folly::LogConfig::operator== ( const LogConfig other) const

Definition at line 22 of file LogConfig.cpp.

References categoryConfigs_, and handlerConfigs_.

Referenced by getHandlerConfigs().

22  {
23  return handlerConfigs_ == other.handlerConfigs_ &&
24  categoryConfigs_ == other.categoryConfigs_;
25 }
CategoryConfigMap categoryConfigs_
Definition: LogConfig.h:86
HandlerConfigMap handlerConfigs_
Definition: LogConfig.h:85
void folly::LogConfig::update ( const LogConfig other)

Update this LogConfig object by merging in settings from another LogConfig.

All LogHandler settings from the other LogConfig will be inserted into this LogConfig. If a log handler with the same name was already defined in this LogConfig it will be replaced with the new settings.

All LogCategory settings from the other LogConfig will be inserted into this LogConfig. If a log category with the same name was already defined in this LogConfig, its settings will be updated with settings from the other LogConfig. However, if the other LogConfig does not define handler settings for the category it will retain its current handler settings.

This method allows LogConfig objects to be combined before applying them. Using LogConfig::update() will produce the same results as if LoggerDB::updateConfig() had been called with both configs sequentially. In other words, this operation:

configA.update(configB); loggerDB.updateConfig(configA);

will produce the same results as:

loggerDB.updateConfig(configA); loggerDB.updateConfig(configA);

Definition at line 31 of file LogConfig.cpp.

References categoryConfigs_, handlerConfigs_, and folly::gen::move.

Referenced by getHandlerConfigs(), and folly::initLogging().

31  {
32  // Update handlerConfigs_ with all of the entries from the other LogConfig.
33  // Any entries already present in our handlerConfigs_ are replaced wholesale.
34  for (const auto& entry : other.handlerConfigs_) {
35  if (entry.second.type.hasValue()) {
36  // This is a complete LogHandlerConfig that should be inserted
37  // or completely replace an existing handler config with this name.
38  auto result = handlerConfigs_.insert(entry);
39  if (!result.second) {
40  result.first->second = entry.second;
41  }
42  } else {
43  // This config is updating an existing LogHandlerConfig rather than
44  // completely replacing it.
45  auto iter = handlerConfigs_.find(entry.first);
46  if (iter == handlerConfigs_.end()) {
47  throw std::invalid_argument(to<std::string>(
48  "cannot update configuration for unknown log handler \"",
49  entry.first,
50  "\""));
51  }
52  iter->second.update(entry.second);
53  }
54  }
55 
56  // Update categoryConfigs_ with all of the entries from the other LogConfig.
57  //
58  // Any entries already present in our categoryConfigs_ are merged: if the new
59  // configuration does not include handler settings our entry's settings are
60  // maintained.
61  for (const auto& entry : other.categoryConfigs_) {
62  auto result = categoryConfigs_.insert(entry);
63  if (!result.second) {
64  auto* existingEntry = &result.first->second;
65  auto oldHandlers = std::move(existingEntry->handlers);
66  *existingEntry = entry.second;
67  if (!existingEntry->handlers.hasValue()) {
68  existingEntry->handlers = std::move(oldHandlers);
69  }
70  }
71  }
72 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
CategoryConfigMap categoryConfigs_
Definition: LogConfig.h:86
HandlerConfigMap handlerConfigs_
Definition: LogConfig.h:85

Member Data Documentation

CategoryConfigMap folly::LogConfig::categoryConfigs_
private

Definition at line 86 of file LogConfig.h.

Referenced by getCategoryConfigs(), LogConfig(), operator==(), and update().

HandlerConfigMap folly::LogConfig::handlerConfigs_
private

Definition at line 85 of file LogConfig.h.

Referenced by getHandlerConfigs(), operator==(), and update().


The documentation for this class was generated from the following files: