Kea  2.3.4-git
config_base.cc
Go to the documentation of this file.
1 // Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #include <config.h>
8 
9 #include <log/logger_manager.h>
10 #include <log/logger_name.h>
12 #include <process/config_base.h>
13 
14 #include <list>
15 
16 using namespace isc::log;
17 using namespace isc::data;
18 
19 namespace isc {
20 namespace process {
21 
22 void
23 ConfigBase::applyLoggingCfg() const {
24  std::list<LoggerSpecification> specs;
25  for (LoggingInfo const& logging_info : logging_info_) {
26  if (logging_info.name_ == getRootLoggerName()) {
27  // Root logger has to be processed first if we expect child loggers
28  // to inherit configuration from it.
29  specs.push_front(logging_info.toSpec());
30  } else {
31  specs.push_back(logging_info.toSpec());
32  }
33  }
34  LoggerManager manager;
35  manager.process(specs.begin(), specs.end());
36 }
37 
38 bool
39 ConfigBase::equals(const ConfigBase& other) const {
40  // If number of loggers is different, then configurations aren't equal.
41  if (logging_info_.size() != other.logging_info_.size()) {
42  return (false);
43  }
44  // Pass through all loggers and try to find the match for each of them
45  // with the loggers from the other configuration. The order doesn't
46  // matter so we can't simply compare the vectors.
47  for (LoggingInfoStorage::const_iterator this_it =
48  logging_info_.begin(); this_it != logging_info_.end();
49  ++this_it) {
50  bool match = false;
51  for (LoggingInfoStorage::const_iterator other_it =
52  other.logging_info_.begin();
53  other_it != other.logging_info_.end(); ++other_it) {
54  if (this_it->equals(*other_it)) {
55  match = true;
56  break;
57  }
58  }
59  // No match found for the particular logger so return false.
60  if (!match) {
61  return (false);
62  }
63  }
64 
65  // Check config control info for equality.
66  if ((config_ctl_info_ && !other.config_ctl_info_) ||
67  (!config_ctl_info_ && other.config_ctl_info_) ||
68  ((config_ctl_info_ && other.config_ctl_info_) &&
69  (!config_ctl_info_->equals(*(other.config_ctl_info_))))) {
70  return (false);
71  }
72 
73  return (true);
74 }
75 
76 void
78  // We will entirely replace loggers in the new configuration.
79  other.logging_info_.clear();
80  for (LoggingInfoStorage::const_iterator it = logging_info_.begin();
81  it != logging_info_.end(); ++it) {
82  other.addLoggingInfo(*it);
83  }
84 
85  // Clone the config control info
86  if (config_ctl_info_) {
87  other.config_ctl_info_.reset(new ConfigControlInfo(*config_ctl_info_));
88  } else {
89  other.config_ctl_info_.reset();
90  }
91 
92  // Clone server tag.
93  other.server_tag_ = server_tag_;
94 }
95 
96 void
98  // Merge logging info.
99  if (!other.logging_info_.empty()) {
100  logging_info_ = other.logging_info_;
101  }
102 
103  // Merge the config control info
104  if (other.config_ctl_info_) {
105  if (config_ctl_info_) {
106  config_ctl_info_->merge(*other.config_ctl_info_);
107  } else {
108  config_ctl_info_ = other.config_ctl_info_;
109  }
110  }
111 
112  // Merge server tag.
113  if (!other.server_tag_.unspecified()) {
114  server_tag_ = other.server_tag_.get();
115  }
116 }
117 
119 ConfigBase::toElement() const {
120  ElementPtr result = Element::createMap();
121 
122  // Was in the Logging global map.
123  if (!logging_info_.empty()) {
124  // Set loggers list
125  ElementPtr loggers = Element::createList();
126  for (LoggingInfoStorage::const_iterator logger =
127  logging_info_.cbegin();
128  logger != logging_info_.cend(); ++logger) {
129  loggers->add(logger->toElement());
130  }
131  result->set("loggers", loggers);
132  }
133 
134  // server-tag
135  if (!server_tag_.unspecified()) {
136  result->set("server-tag", Element::create(server_tag_.get()));
137  }
138 
139  return (result);
140 }
141 
142 } // namespace process
143 } // namespace isc
const std::string & getRootLoggerName()
Get root logger name.
Definition: logger_name.cc:33
void unspecified(bool unspecified)
Modifies the flag that indicates whether the value is specified or unspecified.
Definition: optional.h:136
void addLoggingInfo(const process::LoggingInfo &logging_info)
Sets logging specific configuration.
Definition: config_base.h:50
void process(T start, T finish)
Process Specifications.
Base class for all configurations.
Definition: config_base.h:33
Logger Manager.
T get() const
Retrieves the encapsulated value.
Definition: optional.h:114
Embodies configuration information used during a server&#39;s configuration process.
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
structure that describes one logging entry
Definition: logging_info.h:81
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
Definition: data.cc:1360
Defines the logger used by the top-level component of kea-lfc.
isc::log::Logger logger("asiodns")
Use the ASIO logger.
void merge(ElementPtr element, ConstElementPtr other)
Merges the data from other into element.
Definition: data.cc:1139