From: Tomek Mrugalski Date: Tue, 9 Sep 2014 14:13:59 +0000 (+0200) Subject: [3591] Logging initialization cleaned up X-Git-Tag: rt3470_base~12^2~12 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c24182c20157d1cee0925657669d88028fb76f10;p=thirdparty%2Fkea.git [3591] Logging initialization cleaned up --- diff --git a/src/bin/d2/d_controller.cc b/src/bin/d2/d_controller.cc index 29e3e288df..ee78b63355 100644 --- a/src/bin/d2/d_controller.cc +++ b/src/bin/d2/d_controller.cc @@ -424,17 +424,6 @@ DControllerBase::~DControllerBase() { }; // namespace isc::d2 -// Provide an implementation until we figure out a better way to do this. -void -dhcp::Daemon::loggerInit(const char* log_name, bool verbose) { - setenv("KEA_LOCKFILE_DIR_FROM_BUILD", "/tmp", 1); - setenv("KEA_LOGGER_ROOT", log_name, 0); - setenv("KEA_LOGGER_SEVERITY", (verbose ? "DEBUG":"INFO"), 0); - setenv("KEA_LOGGER_DBGLEVEL", "99", 0); - setenv("KEA_LOGGER_DESTINATION", "stdout", 0); - isc::log::initLogger(); -} - }; // namespace isc std::string diff --git a/src/bin/dhcp4/bundy_controller.cc b/src/bin/dhcp4/bundy_controller.cc index 2b69b77baa..7fb655a018 100644 --- a/src/bin/dhcp4/bundy_controller.cc +++ b/src/bin/dhcp4/bundy_controller.cc @@ -211,12 +211,5 @@ void ControlledDhcpv4Srv::cleanup() { } } -void -Daemon::loggerInit(const char* log_name, bool verbose) { - isc::log::initLogger(log_name, - (verbose ? isc::log::DEBUG : isc::log::INFO), - isc::log::MAX_DEBUG_LEVEL, NULL, true); -} - }; }; diff --git a/src/bin/dhcp4/kea_controller.cc b/src/bin/dhcp4/kea_controller.cc index 926832dbc0..4c7014ad27 100644 --- a/src/bin/dhcp4/kea_controller.cc +++ b/src/bin/dhcp4/kea_controller.cc @@ -165,18 +165,5 @@ void ControlledDhcpv4Srv::cleanup() { // Nothing to do here. No need to disconnect from anything. } -/// This is a logger initialization for JSON file backend. -/// For now, it's just setting log messages to be printed on stdout. -/// @todo: Implement this properly (see #3427) -void Daemon::loggerInit(const char* logger_name, bool verbose) { - - setenv("KEA_LOCKFILE_DIR_FROM_BUILD", "/tmp", 1); - setenv("KEA_LOGGER_ROOT", logger_name, 0); - setenv("KEA_LOGGER_SEVERITY", (verbose ? "DEBUG":"INFO"), 0); - setenv("KEA_LOGGER_DBGLEVEL", "99", 0); - setenv("KEA_LOGGER_DESTINATION", "stdout", 0); - isc::log::initLogger(); -} - }; }; diff --git a/src/bin/dhcp6/bundy_controller.cc b/src/bin/dhcp6/bundy_controller.cc index 00fc924107..c4e12062c1 100644 --- a/src/bin/dhcp6/bundy_controller.cc +++ b/src/bin/dhcp6/bundy_controller.cc @@ -222,12 +222,5 @@ void ControlledDhcpv6Srv::cleanup() { } } -void -Daemon::loggerInit(const char* log_name, bool verbose) { - isc::log::initLogger(log_name, - (verbose ? isc::log::DEBUG : isc::log::INFO), - isc::log::MAX_DEBUG_LEVEL, NULL, true); -} - }; // end of isc::dhcp namespace }; // end of isc namespace diff --git a/src/bin/dhcp6/kea_controller.cc b/src/bin/dhcp6/kea_controller.cc index ff2f2ad347..159827e847 100644 --- a/src/bin/dhcp6/kea_controller.cc +++ b/src/bin/dhcp6/kea_controller.cc @@ -169,18 +169,5 @@ void ControlledDhcpv6Srv::cleanup() { // Nothing to do here. No need to disconnect from anything. } -/// This is a logger initialization for JSON file backend. -/// For now, it's just setting log messages to be printed on stdout. -/// @todo: Implement this properly (see #3427) -void Daemon::loggerInit(const char* logger_name, bool verbose) { - - setenv("KEA_LOCKFILE_DIR_FROM_BUILD", "/tmp", 1); - setenv("KEA_LOGGER_ROOT", logger_name, 0); - setenv("KEA_LOGGER_SEVERITY", (verbose ? "DEBUG":"INFO"), 0); - setenv("KEA_LOGGER_DBGLEVEL", "99", 0); - setenv("KEA_LOGGER_DESTINATION", "stdout", 0); - isc::log::initLogger(); -} - }; }; diff --git a/src/lib/dhcpsrv/daemon.cc b/src/lib/dhcpsrv/daemon.cc index 8116cb9105..21bfec8f3a 100644 --- a/src/lib/dhcpsrv/daemon.cc +++ b/src/lib/dhcpsrv/daemon.cc @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include /// @brief provides default implementation for basic daemon operations @@ -92,5 +94,18 @@ void Daemon::configureLogger(const isc::data::ConstElementPtr& log_config, parser.applyConfiguration(); } +void Daemon::loggerInit(const char*, bool verbose) { + + setenv("KEA_LOCKFILE_DIR_FROM_BUILD", "/tmp", 0); + + // Initialize logger system + isc::log::initLogger(isc::log::getDefaultRootLoggerName().c_str(), + isc::log::DEBUG, isc::log::MAX_DEBUG_LEVEL, + NULL); + + // Apply default configuration (log INFO or DEBUG to stdout) + LogConfigParser::applyDefaultConfiguration(verbose); +} + }; }; diff --git a/src/lib/dhcpsrv/daemon.h b/src/lib/dhcpsrv/daemon.h index c9939a77b2..adc38d8535 100644 --- a/src/lib/dhcpsrv/daemon.h +++ b/src/lib/dhcpsrv/daemon.h @@ -111,8 +111,10 @@ public: /// @brief Initializes logger /// - /// This method initializes logger. Currently its implementation is specific - /// to each configuration backend. + /// This method initializes logging system. It also sets the default + /// output to stdout. This is used in early stages of the startup + /// phase before config file and parsed and proper logging details + /// are known. /// /// @param log_name name used in logger initialization /// @param verbose verbose mode (true usually enables DEBUG messages) diff --git a/src/lib/dhcpsrv/logging.h b/src/lib/dhcpsrv/logging.h index 9cb7a3c698..60230f65a2 100644 --- a/src/lib/dhcpsrv/logging.h +++ b/src/lib/dhcpsrv/logging.h @@ -69,10 +69,11 @@ public: /// @brief Configures default logging /// - /// This method is static, + /// This method is static, so it can be called in the initial phases of + /// the process start-up. /// /// @param verbose specifies verbose mode (true forces DEBUG, debuglevel = 99) - void applyDefaultConfiguration(bool verbose = false); + static void applyDefaultConfiguration(bool verbose = false); private: