Browse Source

[trac976] Ensure reset() resets back to state passed by init()

Stephen Morris 14 years ago
parent
commit
cbe4f685db
2 changed files with 31 additions and 4 deletions
  1. 30 2
      src/lib/log/logger_manager.cc
  2. 1 2
      src/lib/log/logger_manager.h

+ 30 - 2
src/lib/log/logger_manager.cc

@@ -35,8 +35,28 @@ namespace {
 
 // Logger used for logging messages within the logging code itself.
 isc::log::Logger logger("log");
+
+// Static stores for the initialization severity and debug level.
+// These are put in methods to avoid a "static initialization fiasco".
+
+isc::log::Severity& initSeverity() {
+    static isc::log::Severity severity = isc::log::INFO;
+    return (severity);
 }
 
+int& initDebugLevel() {
+    static int dbglevel = 0;
+    return (dbglevel);
+}
+
+std::string& initRootName() {
+    static std::string root("b10root");
+    return (root);
+}
+
+} // Anonymous namespace
+
+
 namespace isc {
 namespace log {
 
@@ -75,6 +95,13 @@ void
 LoggerManager::init(const std::string& root, isc::log::Severity severity,
                     int dbglevel, const char* file)
 {
+    // Save name, severity and debug level for later.  No need to save the
+    // file name as once the local message file is read the messages will
+    // not be lost.
+    initRootName() = root;
+    initSeverity() = severity;
+    initDebugLevel() = dbglevel;
+
     // Create the BIND 10 root logger and set the default severity and
     // debug level.  This is the logger that has the name of the application.
     // All other loggers created in this application will be its children.
@@ -145,10 +172,11 @@ LoggerManager::readLocalMessageFile(const char* file) {
     }
 }
 
-// Reset logging
+// Reset logging to settings passed to init()
 void
 LoggerManager::reset() {
-    LoggerManagerImpl::reset();
+    setRootLoggerName(initRootName());
+    LoggerManagerImpl::reset(initSeverity(), initDebugLevel());
 }
 
 } // namespace log

+ 1 - 2
src/lib/log/logger_manager.h

@@ -97,8 +97,7 @@ public:
 
     /// \brief Reset logging
     ///
-    /// Resets logging to default (just the root logger output INFO or above
-    /// messages to the console.
+    /// Resets logging to whatever was set in the call to init().
     static void reset();
 
     /// \brief Read local message file