Browse Source

[trac976] Add missing Logger::getEffectiveDebugLevel()

The method was in the LoggerImp class but omitted from
Logger.  This was a small fix so incorporated in this ticket.
Stephen Morris 14 years ago
parent
commit
0c8063199f
3 changed files with 52 additions and 1 deletions
  1. 8 0
      src/lib/log/logger.cc
  2. 8 1
      src/lib/log/logger.h
  3. 36 0
      src/lib/log/tests/logger_unittest.cc

+ 8 - 0
src/lib/log/logger.cc

@@ -74,6 +74,14 @@ Logger::getDebugLevel() {
     return (getLoggerPtr()->getDebugLevel());
 }
 
+// Effective debug level (only relevant if messages of severity DEBUG are being
+// logged).
+
+int
+Logger::getEffectiveDebugLevel() {
+    return (getLoggerPtr()->getEffectiveDebugLevel());
+}
+
 // Check on the current severity settings
 
 bool

+ 8 - 1
src/lib/log/logger.h

@@ -59,7 +59,7 @@ namespace log {
 /// In this way, individual libraries can have their own loggers without
 /// worrying about the program in which they are used, but:
 /// - The origin of the message will be clearly identified.
-/// - The same component can have different options (e.g. logging severity)
+/// - The same component can have different options 736#comment:12(e.g. logging severity)
 /// in different programs at the same time.
 /// 
 /// \section LoggingApiLoggingMessages Logging Messages
@@ -139,6 +139,13 @@ public:
     /// whether the severity is set to debug.
     virtual int getDebugLevel();
 
+    /// \brief Get Effective Debug Level for Logger
+    ///
+    /// \return The effective debug level of the logger.  This is the same
+    /// as getDebugLevel() if the logger has a debug level set, but otherwise
+    /// is the debug level of the parent.
+    virtual int getEffectiveDebugLevel();
+
     /// \brief Returns if Debug Message Should Be Output
     ///
     /// \param dbglevel Level for which debugging is checked.  Debugging is

+ 36 - 0
src/lib/log/tests/logger_unittest.cc

@@ -164,6 +164,42 @@ TEST_F(LoggerTest, SeverityInheritance) {
     EXPECT_EQ(isc::log::DEFAULT, parent.getSeverity());
     EXPECT_EQ(isc::log::DEFAULT, child.getSeverity());
 
+    // Set the severity of the parent to debug and check what is
+    // reported by the child.
+    parent.setSeverity(isc::log::DEBUG, 42);
+    EXPECT_EQ(42, parent.getDebugLevel());
+    EXPECT_EQ(0,  child.getDebugLevel());
+    EXPECT_EQ(42, child.getEffectiveDebugLevel());
+
+    // Setting the child to DEBUG severity should set its own
+    // debug level.
+    child.setSeverity(isc::log::DEBUG, 53);
+    EXPECT_EQ(53,  child.getDebugLevel());
+    EXPECT_EQ(53, child.getEffectiveDebugLevel());
+
+    // If the child severity is set to something other than DEBUG,
+    // the debug level should be reported as 0.
+    child.setSeverity(isc::log::ERROR);
+    EXPECT_EQ(0,  child.getDebugLevel());
+    EXPECT_EQ(0, child.getEffectiveDebugLevel());
+}
+
+// Check that changing the parent and child debug level does not affect
+// the other.
+
+TEST_F(LoggerTest, DebugLevelInheritance) {
+
+    // Create two loggers.  We cheat here as we know that the underlying
+    // implementation will set a parent-child relationship if the loggers
+    // are named <parent> and <parent>.<child>.
+    Logger parent("alpha");
+    Logger child("alpha.beta");
+
+    // By default, newly created loggers should have a level of DEFAULT
+    // (i.e. default to parent)
+    EXPECT_EQ(isc::log::DEFAULT, parent.getSeverity());
+    EXPECT_EQ(isc::log::DEFAULT, child.getSeverity());
+
     // Set the severity of the child to something other than the default -
     // check it changes and that of the parent does not.
     child.setSeverity(isc::log::INFO);