Browse Source

[3591] Logging initialization cleaned up

Tomek Mrugalski 10 years ago
parent
commit
c24182c201

+ 0 - 11
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

+ 0 - 7
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);
-}
-
 };
 };

+ 0 - 13
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();
-}
-
 };
 };

+ 0 - 7
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

+ 0 - 13
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();
-}
-
 };
 };

+ 15 - 0
src/lib/dhcpsrv/daemon.cc

@@ -18,6 +18,8 @@
 #include <cc/data.h>
 #include <boost/bind.hpp>
 #include <logging.h>
+#include <log/logger_name.h>
+#include <log/logger_support.h>
 #include <errno.h>
 
 /// @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);
+}
+
 };
 };

+ 4 - 2
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)

+ 3 - 2
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: