Kea 1.5.0
logging_info.cc
Go to the documentation of this file.
1// Copyright (C) 2014-2018 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>
9#include <process/daemon.h>
10#include <log/logger_name.h>
11
12using namespace isc::log;
13using namespace isc::data;
14
15namespace isc {
16namespace process {
17
18bool
20 return (output_ == other.output_ &&
21 maxver_ == other.maxver_ &&
22 maxsize_ == other.maxsize_ &&
23 flush_ == other.flush_);
24}
25
29
30 // Set output
31 result->set("output", Element::create(output_));
32 // Set maxver
33 result->set("maxver", Element::create(maxver_));
34 // Set maxsize
35 result->set("maxsize", Element::create(static_cast<long long>(maxsize_)));
36 // Set flush
37 result->set("flush", Element::create(flush_));
38
39 return(result);
40}
41
43 : name_("kea"), severity_(isc::log::INFO), debuglevel_(0) {
44 // If configuration Manager is in the verbose mode, we need to modify the
45 // default settings.
46 if (Daemon::getVerbose()) {
48 debuglevel_ = 99;
49 }
50
51 // If the process has set the non-empty name for the default logger,
52 // let's use this name.
53 std::string default_logger = Daemon::getDefaultLoggerName();
54 if (!default_logger.empty()) {
55 name_ = default_logger;
56 }
57
58 // Add a default logging destination in case use hasn't provided a
59 // logger specification.
61 dest.output_ = "stdout";
62 destinations_.push_back(dest);
63}
64
65bool
66LoggingInfo::equals(const LoggingInfo& other) const {
67 // If number of destinations aren't equal, the objects are not equal.
68 if (destinations_.size() != other.destinations_.size()) {
69 return (false);
70 }
71 // If there is the same number of logging destinations verify that the
72 // destinations are equal. The order doesn't matter to we don't expect
73 // that they are at the same index of the vectors.
74 for (std::vector<LoggingDestination>::const_iterator
75 it_this = destinations_.begin();
76 it_this != destinations_.end();
77 ++it_this) {
78 bool match = false;
79 for (std::vector<LoggingDestination>::const_iterator
80 it_other = other.destinations_.begin();
81 it_other != other.destinations_.end();
82 ++it_other) {
83 if (it_this->equals(*it_other)) {
84 match = true;
85 break;
86 }
87 }
88 if (!match) {
89 return (false);
90 }
91 }
92
93 // Logging destinations are equal. Check the rest of the parameters for
94 // equality.
95 return (name_ == other.name_ &&
96 severity_ == other.severity_ &&
97 debuglevel_ == other.debuglevel_);
98}
99
102 static const std::string STDOUT = "stdout";
103 static const std::string STDERR = "stderr";
104 static const std::string SYSLOG = "syslog";
105 static const std::string SYSLOG_COLON = "syslog:";
106
108
109 // Go over logger destinations and create output options accordingly.
110 for (std::vector<LoggingDestination>::const_iterator dest =
111 destinations_.begin(); dest != destinations_.end(); ++dest) {
112
113 OutputOption option;
114 // Set up output option according to destination specification
115 if (dest->output_ == STDOUT) {
118
119 } else if (dest->output_ == STDERR) {
122
123 } else if (dest->output_ == SYSLOG) {
125 // Use default specified in OutputOption constructor for the
126 // syslog destination
127
128 } else if (dest->output_.find(SYSLOG_COLON) == 0) {
130 // Must take account of the string actually being "syslog:"
131 if (dest->output_ == SYSLOG_COLON) {
132 // The expected syntax is syslog:facility. User skipped
133 // the logging name, so we'll just use the default ("kea")
135
136 } else {
137 // Everything else in the string is the facility name
138 option.facility = dest->output_.substr(SYSLOG_COLON.size());
139 }
140
141 } else {
142 // Not a recognized destination, assume a file.
144 option.filename = dest->output_;
145 option.maxsize = dest->maxsize_;
146 option.maxver = dest->maxver_;
147 }
148
149 // Copy the immediate flush flag
150 option.flush = dest->flush_;
151
152 // ... and set the destination
153 spec.addOutputOption(option);
154 }
155
156 return (spec);
157}
158
162 // Set user context
163 contextToElement(result);
164 // Set name
165 result->set("name", Element::create(name_));
166 // Set output_options if not empty
167 if (!destinations_.empty()) {
169 for (std::vector<LoggingDestination>::const_iterator dest =
170 destinations_.cbegin();
171 dest != destinations_.cend(); ++dest) {
172 options->add(dest->toElement());
173 }
174 result->set("output_options", options);
175 }
176 // Set severity
177 std::string severity;
178 switch (severity_) {
179 case isc::log::DEBUG:
180 severity = "DEBUG";
181 break;
182 case isc::log::INFO:
183 severity = "INFO";
184 break;
185 case isc::log::WARN:
186 severity = "WARN";
187 break;
188 case isc::log::ERROR:
189 severity = "ERROR";
190 break;
191 case isc::log::FATAL:
192 severity = "FATAL";
193 break;
194 case isc::log::NONE:
195 severity = "NONE";
196 break;
197 default:
198 isc_throw(ToElementError, "illegal severity: " << severity_);
199 break;
200 }
201 result->set("severity", Element::create(severity));
202 // Set debug level
203 result->set("debuglevel", Element::create(debuglevel_));
204 return (result);
205}
206
207} // end of namespace isc::dhcp
208} // end of namespace isc
Cannot unparse error.
static ElementPtr create(const Position &pos=ZERO_POSITION())
Definition: data.cc:223
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
Definition: data.cc:268
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
Definition: data.cc:263
void addOutputOption(const OutputOption &option)
Add output option.
static bool getVerbose()
Returns if running in verbose mode.
Definition: daemon.cc:84
static std::string getDefaultLoggerName()
Returns default logger name.
Definition: daemon.h:208
structure that describes one logging entry
Definition: logging_info.h:76
LoggingInfo()
Default constructor.
Definition: logging_info.cc:42
int debuglevel_
debuglevel (used when severity_ == DEBUG)
Definition: logging_info.h:88
bool equals(const LoggingInfo &other) const
Compares two objects for equality.
Definition: logging_info.cc:66
isc::log::LoggerSpecification toSpec() const
Converts logger configuration to a spec.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
std::string name_
logging name
Definition: logging_info.h:80
std::vector< LoggingDestination > destinations_
specific logging destinations
Definition: logging_info.h:91
isc::log::Severity severity_
describes logging severity
Definition: logging_info.h:83
const Name & name_
Definition: dns/message.cc:693
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< Element > ElementPtr
Definition: data.h:22
const std::string & getDefaultRootLoggerName()
Returns the default ('kea') root logger name.
Definition: logger_name.cc:37
Defines the logger used by the top-level component of kea-dhcp-ddns.
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.
Definition: user_context.cc:15
Destination destination
Members.
Definition: output_option.h:61
bool flush
true to flush after each message
Definition: output_option.h:63
size_t maxsize
0 if no maximum size
Definition: output_option.h:66
unsigned int maxver
Maximum versions (none if <= 0)
Definition: output_option.h:67
std::string facility
syslog facility
Definition: output_option.h:64
Stream stream
stdout/stderr if console output
Definition: output_option.h:62
std::string filename
Filename if file output.
Definition: output_option.h:65
Defines single logging destination.
Definition: logging_info.h:23
int maxver_
Maximum number of log files in rotation.
Definition: logging_info.h:33
std::string output_
defines logging destination output
Definition: logging_info.h:30
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: logging_info.cc:27
bool equals(const LoggingDestination &other) const
Compares two objects for equality.
Definition: logging_info.cc:19
uint64_t maxsize_
Maximum log file size.
Definition: logging_info.h:36
bool flush_
Immediate flush.
Definition: logging_info.h:39