Prevent fault when using one of the LevelChange constructors (#368)
diff --git a/src/main/include/log4cxx/levelchange.h b/src/main/include/log4cxx/levelchange.h
index df2f6f9..1a5ec57 100644
--- a/src/main/include/log4cxx/levelchange.h
+++ b/src/main/include/log4cxx/levelchange.h
@@ -52,7 +52,7 @@
}
/// Set \c otherCategory to the level of \c thisCategory
LevelChange(const LoggerPtr& otherCategory, const LoggerPtr& thisCategory)
- : LevelChange(otherCategory, m_otherCategory->getLevel())
+ : LevelChange(otherCategory, thisCategory->getLevel())
{
}
/// Set the logger named \c otherCategory to \c level
diff --git a/src/test/cpp/levelchangetestcase.cpp b/src/test/cpp/levelchangetestcase.cpp
index 85ea1eb..c935d93 100644
--- a/src/test/cpp/levelchangetestcase.cpp
+++ b/src/test/cpp/levelchangetestcase.cpp
@@ -124,12 +124,22 @@
processor.DoStep1();
LOGUNIT_ASSERT_EQUAL(appender->count, initialCount);
{
- LevelChange x(LOG4CXX_STR("ComplexProcessing"), myLogger);
+ LevelChange ctx(getLogger(LOG4CXX_STR("ComplexProcessing")), myLogger);
processor.DoStep2();
// Check the ComplexProcessing debug request was sent to the appender
LOGUNIT_ASSERT_EQUAL(appender->count, initialCount + 1);
}
+ // Check the ComplexProcessing debug request is not sent to the appender
+ processor.DoStep1();
+ LOGUNIT_ASSERT_EQUAL(appender->count, initialCount + 1);
+ {
+ LevelChange ctx(LOG4CXX_STR("ComplexProcessing"), myLogger);
+ processor.DoStep2();
+ // Check the ComplexProcessing debug request was sent to the appender
+ LOGUNIT_ASSERT_EQUAL(appender->count, initialCount + 2);
+ }
+
// Check the ComplexProcessing debug request is no longer sent to the appender
auto finalCount = appender->count;
processor.DoStep3();