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 fb5fad55 Allow the currently executing program file path components to
be used in a properties configuration file (#572)
fb5fad55 is described below
commit fb5fad5537725efed6788e76cc60409d5985e33a
Author: Stephen Webb <[email protected]>
AuthorDate: Wed Dec 24 12:49:29 2025 +1100
Allow the currently executing program file path components to be used in a
properties configuration file (#572)
* Make Properties::load additive
---
src/main/cpp/properties.cpp | 7 ++-----
src/test/cpp/autoconfiguretestcase.cpp | 24 ++++++++++++++--------
.../resources/input/autoConfigureTest.properties | 2 +-
3 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/src/main/cpp/properties.cpp b/src/main/cpp/properties.cpp
index dfa72f83..03651006 100644
--- a/src/main/cpp/properties.cpp
+++ b/src/main/cpp/properties.cpp
@@ -442,11 +442,8 @@ LogString Properties::get(const LogString& key) const
void Properties::load(InputStreamPtr inStream)
{
Pool pool;
- auto lineReader = std::make_shared<InputStreamReader>(inStream,
CharsetDecoder::getISOLatinDecoder());
- LogString contents = lineReader->read(pool);
- properties->clear();
- PropertyParser parser;
- parser.parse(contents, *this);
+ auto contents = InputStreamReader(inStream,
CharsetDecoder::getISOLatinDecoder()).read(pool);
+ PropertyParser().parse(contents, *this);
}
std::vector<LogString> Properties::propertyNames() const
diff --git a/src/test/cpp/autoconfiguretestcase.cpp
b/src/test/cpp/autoconfiguretestcase.cpp
index da634bee..df21032f 100644
--- a/src/test/cpp/autoconfiguretestcase.cpp
+++ b/src/test/cpp/autoconfiguretestcase.cpp
@@ -17,6 +17,7 @@
#include "logunit.h"
#include <log4cxx/logger.h>
#include <log4cxx/logmanager.h>
+#include <log4cxx/fileappender.h>
#include <log4cxx/defaultconfigurator.h>
#include <log4cxx/helpers/bytebuffer.h>
#include <log4cxx/helpers/exception.h>
@@ -57,6 +58,7 @@ using namespace log4cxx;
LOGUNIT_CLASS(AutoConfigureTestCase)
{
LOGUNIT_TEST_SUITE(AutoConfigureTestCase);
+ LOGUNIT_TEST(testSetup);
LOGUNIT_TEST(test1);
LOGUNIT_TEST(test2);
LOGUNIT_TEST_SUITE_END();
@@ -90,11 +92,10 @@ public:
void setUp()
{
-#if LOG4CXX_HAS_FILESYSTEM_PATH
- auto fileName =
spi::Configurator::properties().getProperty(LOG4CXX_STR("PROGRAM_FILE_PATH.STEM"));
-#else
- LogString fileName = LOG4CXX_STR("autoconfiguretestcase");
+#if !LOG4CXX_HAS_FILESYSTEM_PATH
+
spi::Configurator::properties().setProperty(LOG4CXX_STR("PROGRAM_FILE_PATH.STEM"),
LOG4CXX_STR("autoconfiguretestcase"));
#endif
+ auto fileName =
spi::Configurator::properties().getProperty(LOG4CXX_STR("PROGRAM_FILE_PATH.STEM"));
auto lsTempDir =
helpers::OptionConverter::getSystemProperty(LOG4CXX_STR("TEMP"),
LOG4CXX_STR("/tmp"));
copyPropertyFile(lsTempDir, fileName);
DefaultConfigurator::setConfigurationWatchSeconds(1);
@@ -102,11 +103,7 @@ public:
{ lsTempDir
};
std::vector<LogString> names
-#if LOG4CXX_HAS_FILESYSTEM_PATH
{ LOG4CXX_STR("${PROGRAM_FILE_PATH.STEM}.properties")
-#else
- { LOG4CXX_STR("autoconfiguretestcase.properties")
-#endif
};
std::tie(m_status, m_configFile) =
DefaultConfigurator::configureFromFile(paths, names);
}
@@ -120,7 +117,16 @@ public:
apr_sleep(200000);
}
- void test1()
+ void testSetup()
+ {
+ auto fa =
LOG4CXX_NS::cast<FileAppender>(LogManager::getRootLogger()->getAppender(LOG4CXX_STR("A1")));
+ LOGUNIT_ASSERT(fa);
+ auto fileName =
spi::Configurator::properties().getProperty(LOG4CXX_STR("PROGRAM_FILE_PATH.STEM"));
+ File logFile(fa->getFile());
+ LOGUNIT_ASSERT_EQUAL(fileName + LOG4CXX_STR(".log"),
logFile.getName());
+ }
+
+ void test1()
{
LOGUNIT_ASSERT_EQUAL(m_status,
spi::ConfigurationStatus::Configured);
LOGUNIT_ASSERT(File(m_configFile).exists(m_pool));
diff --git a/src/test/resources/input/autoConfigureTest.properties
b/src/test/resources/input/autoConfigureTest.properties
index 1187d130..b91cf129 100644
--- a/src/test/resources/input/autoConfigureTest.properties
+++ b/src/test/resources/input/autoConfigureTest.properties
@@ -16,7 +16,7 @@
log4j.rootCategory=INFO, A1
log4j.appender.A1=org.apache.log4j.FileAppender
-log4j.appender.A1.File=output/autoConfigureTest.log
+log4j.appender.A1.File=output/${PROGRAM_FILE_PATH.STEM}.log
log4j.appender.A1.Append=false
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%m%n