summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/generic/util/logging.h7
-rw-r--r--tests/test_logging.cc30
2 files changed, 27 insertions, 10 deletions
diff --git a/src/generic/util/logging.h b/src/generic/util/logging.h
index a21b8e42..1ca037f6 100644
--- a/src/generic/util/logging.h
+++ b/src/generic/util/logging.h
@@ -56,9 +56,8 @@ namespace aptitude
WARN_LEVEL = 3,
ERROR_LEVEL = 4,
FATAL_LEVEL = 5,
- /** \brief The OFF level is special: messages logged at it
- * are never seen, even if the logger has been configured
- * to show them.
+ /** \brief The OFF level is special: loggers set to this
+ * level never display any messages.
*/
OFF_LEVEL = INT_MIN
};
@@ -112,7 +111,7 @@ namespace aptitude
bool isEnabledFor(log_level l) const
{
return
- l != OFF_LEVEL &&
+ effectiveLevel != OFF_LEVEL &&
l >= effectiveLevel;
}
diff --git a/tests/test_logging.cc b/tests/test_logging.cc
index b1add525..af4d506a 100644
--- a/tests/test_logging.cc
+++ b/tests/test_logging.cc
@@ -336,12 +336,12 @@ TEST_F(LoggingTest, testIsEnabledOff)
EXPECT_EQ(OFF_LEVEL, root->getEffectiveLevel());
- EXPECT_TRUE( root->isEnabledFor(FATAL_LEVEL) );
- EXPECT_TRUE( root->isEnabledFor(ERROR_LEVEL) );
- EXPECT_TRUE( root->isEnabledFor(WARN_LEVEL) );
- EXPECT_TRUE( root->isEnabledFor(INFO_LEVEL) );
- EXPECT_TRUE( root->isEnabledFor(DEBUG_LEVEL) );
- EXPECT_TRUE( root->isEnabledFor(TRACE_LEVEL) );
+ EXPECT_TRUE( !root->isEnabledFor(FATAL_LEVEL) );
+ EXPECT_TRUE( !root->isEnabledFor(ERROR_LEVEL) );
+ EXPECT_TRUE( !root->isEnabledFor(WARN_LEVEL) );
+ EXPECT_TRUE( !root->isEnabledFor(INFO_LEVEL) );
+ EXPECT_TRUE( !root->isEnabledFor(DEBUG_LEVEL) );
+ EXPECT_TRUE( !root->isEnabledFor(TRACE_LEVEL) );
EXPECT_TRUE( !root->isEnabledFor(OFF_LEVEL) );
}
@@ -459,6 +459,24 @@ TEST_F(LoggingTest, testConnectMessageLoggedCanBeDisconnected)
// that each test uses msg1 for a log that should get through, and
// msg2 for a log that shouldn't.
+TEST_F(LoggingTest, testOffMeansOff)
+{
+ LoggerPtr root = getLogger("");
+ LoggingReceiver receiver;
+
+ EXPECT_NO_LOGS(receiver);
+
+ connect(receiver, root);
+ root->setLevel(OFF_LEVEL);
+
+ LOG_TRACE(root, "trace");
+ LOG_DEBUG(root, "debug");
+ LOG_INFO(root, "info");
+ LOG_WARN(root, "warn");
+ LOG_ERROR(root, "error");
+ LOG_FATAL(root, "fatal");
+}
+
TEST_F(LoggingTest, testLogTrace)
{
LoggerPtr root = getLogger("");