Skip to content

Commit

Permalink
Prevent fault when using one of the LevelChange constructors (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
swebb2066 authored Apr 19, 2024
1 parent dc06736 commit d8048cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/include/log4cxx/levelchange.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace LOG4CXX_NS
}
/// 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
Expand Down
12 changes: 11 additions & 1 deletion src/test/cpp/levelchangetestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,22 @@ LOGUNIT_CLASS(LevelChangeTestCase)
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();
Expand Down

0 comments on commit d8048cc

Please sign in to comment.