BIND 10 trac976, updated. 0c8063199fe37278da7fe03adb5723deb4263f82 [trac976] Add missing Logger::getEffectiveDebugLevel()
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Jun 8 16:13:50 UTC 2011
The branch, trac976 has been updated
via 0c8063199fe37278da7fe03adb5723deb4263f82 (commit)
via e08c212ea82bf00c90eec566b1058862b82b78bf (commit)
from 63f62558f6490de53d57504ac48076165f18b9e8 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 0c8063199fe37278da7fe03adb5723deb4263f82
Author: Stephen Morris <stephen at isc.org>
Date: Wed Jun 8 17:12:49 2011 +0100
[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.
commit e08c212ea82bf00c90eec566b1058862b82b78bf
Author: Stephen Morris <stephen at isc.org>
Date: Wed Jun 8 16:54:26 2011 +0100
[trac976] Add ability to supress messages in unit tests
Allow default logging severity for unit tests to be specified
and overridden by an environment variable.
-----------------------------------------------------------------------
Summary of changes:
src/lib/log/logger.cc | 8 +++++++
src/lib/log/logger.h | 9 +++++++-
src/lib/log/logger_support.cc | 4 +--
src/lib/log/logger_support.h | 10 +++++---
src/lib/log/tests/logger_unittest.cc | 36 ++++++++++++++++++++++++++++++++++
5 files changed, 59 insertions(+), 8 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/log/logger.cc b/src/lib/log/logger.cc
index 2cdc990..5a35d36 100644
--- a/src/lib/log/logger.cc
+++ b/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
diff --git a/src/lib/log/logger.h b/src/lib/log/logger.h
index f381c7e..9b61d37 100644
--- a/src/lib/log/logger.h
+++ b/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
diff --git a/src/lib/log/logger_support.cc b/src/lib/log/logger_support.cc
index a172e0d..ea2f0ab 100644
--- a/src/lib/log/logger_support.cc
+++ b/src/lib/log/logger_support.cc
@@ -51,7 +51,7 @@ initLogger(const string& root, isc::log::Severity severity, int dbglevel,
}
/// Logger Run-Time Initialization via Environment Variables
-void initLogger() {
+void initLogger(isc::log::Severity severity, int dbglevel) {
// Root logger name is defined by the environment variable B10_LOGGER_ROOT.
// If not present, the name is "b10root".
@@ -65,7 +65,6 @@ void initLogger() {
// B10_LOGGER_SEVERITY, and can be one of "DEBUG", "INFO", "WARN", "ERROR"
// of "FATAL". Note that the string must be in upper case with no leading
// of trailing blanks.
- isc::log::Severity severity = isc::log::INFO;
const char* sev_char = getenv("B10_LOGGER_SEVERITY");
if (sev_char) {
severity = isc::log::getSeverity(sev_char);
@@ -73,7 +72,6 @@ void initLogger() {
// If the severity is debug, get the debug level (environment variable
// B10_LOGGER_DBGLEVEL), which should be in the range 0 to 99.
- int dbglevel = 0;
if (severity == isc::log::DEBUG) {
const char* dbg_char = getenv("B10_LOGGER_DBGLEVEL");
if (dbg_char) {
diff --git a/src/lib/log/logger_support.h b/src/lib/log/logger_support.h
index 385ed0a..8fcfab5 100644
--- a/src/lib/log/logger_support.h
+++ b/src/lib/log/logger_support.h
@@ -55,13 +55,14 @@ void initLogger(const std::string& root,
/// Severity of messages that will be logged. This must be one of the strings
/// "DEBUG", "INFO", "WARN", "ERROR", "FATAL" or "NONE". (Must be upper case
/// and must not contain leading or trailing spaces.) If not specified (or if
-/// specified but incorrect), the default for the logging system will be used
-/// (currently INFO).
+/// specified but incorrect), the default passed as argument to this function
+/// (currently INFO) will be used.
///
/// B10_LOGGER_DBGLEVEL
/// Ignored if the level is not DEBUG, this should be a number between 0 and
/// 99 indicating the logging severity. The default is 0. If outside these
-/// limits or if not a number, a value of 0 is used.
+/// limits or if not a number, The value passed to this function (default
+/// of 0) is used.
///
/// B10_LOGGER_LOCALMSG
/// If defined, the path specification of a file that contains message
@@ -71,7 +72,8 @@ void initLogger(const std::string& root,
///
/// This function is most likely to be called from unit test programs.
-void initLogger();
+void initLogger(isc::log::Severity severity = isc::log::INFO,
+ int dbglevel = 0);
} // namespace log
} // namespace isc
diff --git a/src/lib/log/tests/logger_unittest.cc b/src/lib/log/tests/logger_unittest.cc
index e15c0a0..2b4a3b6 100644
--- a/src/lib/log/tests/logger_unittest.cc
+++ b/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);
More information about the bind10-changes
mailing list