This is an automated email from the ASF dual-hosted git repository.
swebb2066 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
The following commit(s) were added to refs/heads/master by this push:
new 2aa1e365 PropertyConfigurator reporting configured state for invalid
appenders (#662)
2aa1e365 is described below
commit 2aa1e3652d2d91ed83bb833c711b31717edeb1e9
Author: jmestwa-coder <[email protected]>
AuthorDate: Thu May 14 06:45:00 2026 +0530
PropertyConfigurator reporting configured state for invalid appenders (#662)
---
src/main/cpp/propertyconfigurator.cpp | 3 ++-
src/test/cpp/propertyconfiguratortest.cpp | 22 ++++++++++++++++++++++
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/src/main/cpp/propertyconfigurator.cpp
b/src/main/cpp/propertyconfigurator.cpp
index 9c1fdd24..bd244535 100644
--- a/src/main/cpp/propertyconfigurator.cpp
+++ b/src/main/cpp/propertyconfigurator.cpp
@@ -603,5 +603,6 @@ void PropertyConfigurator::registryPut(const AppenderPtr&
appender)
AppenderPtr PropertyConfigurator::registryGet(const LogString& name)
{
- return (*m_priv->registry)[name];
+ auto it = m_priv->registry->find(name);
+ return (it == m_priv->registry->end()) ? AppenderPtr() : it->second;
}
diff --git a/src/test/cpp/propertyconfiguratortest.cpp
b/src/test/cpp/propertyconfiguratortest.cpp
index 2d57ee67..64357d60 100644
--- a/src/test/cpp/propertyconfiguratortest.cpp
+++ b/src/test/cpp/propertyconfiguratortest.cpp
@@ -31,6 +31,7 @@ LOGUNIT_CLASS(PropertyConfiguratorTest)
LOGUNIT_TEST(testInherited);
LOGUNIT_TEST(testNull);
LOGUNIT_TEST(testAppenderThreshold);
+ LOGUNIT_TEST(testInvalidAppenderBehavesNotConfigured);
LOGUNIT_TEST_SUITE_END();
public:
@@ -88,6 +89,27 @@ public:
LogManager::resetConfiguration();
}
+ void testInvalidAppenderBehavesNotConfigured()
+ {
+ Properties props;
+ props.put(LOG4CXX_STR("log4j.rootLogger"),
LOG4CXX_STR("DEBUG,BAD"));
+ props.put(LOG4CXX_STR("log4j.appender.BAD"),
LOG4CXX_STR("does.not.Exist"));
+
+ auto status = PropertyConfigurator::configure(props);
+
+ // Expect: invalid appender config should result in
NotConfigured
+ LOGUNIT_ASSERT_EQUAL(status,
spi::ConfigurationStatus::NotConfigured);
+
+ // Repository should not be marked configured
+ LOGUNIT_ASSERT_EQUAL(false,
LogManager::getLoggerRepository()->isConfigured());
+
+ // Root logger should have no appenders
+ LoggerPtr root(Logger::getRootLogger());
+ LOGUNIT_ASSERT_EQUAL((size_t)0, root->getAllAppenders().size());
+
+ LogManager::resetConfiguration();
+ }
+
};