11#include <boost/lexical_cast.hpp>
31 :config_(storage), verbose_(false) {
34 "configuration, so parsed data can be stored there");
43 for (
auto const& logger : loggers->listValue()) {
44 parseConfigEntry(logger);
60 info.clearDestinations();
65 info.setContext(user_context);
71 isc_throw(BadValue,
"loggers entry does not have a mandatory 'name' "
72 "element (" << entry->getPosition() <<
")");
74 info.name_ = name_ptr->stringValue();
93 info.debuglevel_ = boost::lexical_cast<int>(debuglevel_ptr->str());
94 if ( (
info.debuglevel_ < 0) || (
info.debuglevel_ > 99) ) {
99 isc_throw(BadValue,
"Unsupported debuglevel value "
100 << debuglevel_ptr->intValue()
101 <<
", expected 0-99 ("
102 << debuglevel_ptr->getPosition() <<
")");
111 info.debuglevel_ = 99;
117 if (output_options && deprecated_output_options) {
118 isc_throw(BadValue,
"Only one of 'output-options' and 'output_options' may be specified.");
121 if (deprecated_output_options) {
123 output_options = deprecated_output_options;
124 ElementPtr mutable_element = boost::const_pointer_cast<Element>(entry);
125 mutable_element->remove(
"output_options");
126 mutable_element->set(
"output-options", output_options);
129 if (output_options) {
130 parseOutputOptions(
info.destinations_, output_options);
133 config_->addLoggingInfo(info);
138 if (!log_path_checker_ || reset) {
139 log_path_checker_.reset(
new PathChecker(LOGFILE_DIR,
"KEA_LOG_FILE_DIR"));
140 if (!explicit_path.empty()) {
141 log_path_checker_->getPath(
true, explicit_path);
145 return (log_path_checker_->getPath());
150 if (!log_path_checker_) {
155 return (log_path_checker_->validatePath(logpath));
163void LogConfigParser::parseOutputOptions(std::vector<LoggingDestination>& destination,
165 if (!output_options) {
169 for (
auto const& output_option : output_options->listValue()) {
171 LoggingDestination dest;
176 "element (" << output_option->getPosition() <<
")");
179 auto output_str = output->stringValue();
180 if ((output_str ==
"stdout") ||
181 (output_str ==
"stderr") ||
182 (output_str ==
"syslog") ||
183 (output_str.find(
"syslog:") == 0)) {
184 dest.output_ = output_str;
188 }
catch (
const std::exception& ex) {
189 isc_throw(BadValue,
"invalid path in `output`: " << ex.what()
190 <<
" (" << output_option->getPosition() <<
")");
196 dest.maxver_ = boost::lexical_cast<int>(maxver_ptr->str());
201 dest.maxsize_ = boost::lexical_cast<uint64_t>(maxsize_ptr->str());
206 dest.flush_ = flush_ptr->boolValue();
211 dest.pattern_ = pattern->stringValue();
214 destination.push_back(dest);
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
LogConfigParser(const ConfigPtr &storage)
Constructor.
static std::string getLogPath(bool reset=false, const std::string explicit_path="")
Fetches the supported log file path.
static std::string validatePath(const std::string logpath)
Validates a library path against the supported path for log files.
void parseConfiguration(const isc::data::ConstElementPtr &log_config, bool verbose=false)
Parses specified configuration.
Embodies a supported path against which file paths can be validated.
A generic exception that is thrown if a parameter given violates security check but enforcement is la...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Logging initialization functions.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
isc::log::Severity getSeverity(const std::string &sev_str)
Returns the isc::log::Severity value represented by the given string.
isc::log::Logger dctl_logger("dctl")
Defines the logger used within libkea-process library.
boost::shared_ptr< ConfigBase > ConfigPtr
Non-const pointer to the ConfigBase.
const isc::log::MessageID DCTL_DEPRECATED_OUTPUT_OPTIONS
const isc::log::MessageID DCTL_LOG_PATH_SECURITY_WARNING
boost::shared_ptr< PathChecker > PathCheckerPtr
Defines a pointer to a PathChecker.
Defines the logger used by the top-level component of kea-lfc.