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 561657ea Improve configuration file samples in web-site documentation
(#536)
561657ea is described below
commit 561657ea967a13e051a3a93c9a4008b4e366e9d4
Author: Stephen Webb <[email protected]>
AuthorDate: Sat Sep 13 12:43:53 2025 +1000
Improve configuration file samples in web-site documentation (#536)
* Use illustrative vendor/product names in config4.cpp
* Make sure the code agrees with the documentation
* Remove unhelpful references to log4j
---
src/examples/cpp/com/foo/product_version.h | 4 ++--
src/main/cpp/system.cpp | 16 ++++++++++------
src/main/include/log4cxx/spi/configurator.h | 11 +++++------
src/site/markdown/configuration-samples.md | 14 +++++++-------
4 files changed, 24 insertions(+), 21 deletions(-)
diff --git a/src/examples/cpp/com/foo/product_version.h
b/src/examples/cpp/com/foo/product_version.h
index 56c51221..805124c4 100644
--- a/src/examples/cpp/com/foo/product_version.h
+++ b/src/examples/cpp/com/foo/product_version.h
@@ -17,9 +17,9 @@
std::string getVendorFolder()
{
- return "ApacheSoftwareFoundation";
+ return "Foo";
}
std::string getProductFolder()
{
- return "Logging";
+ return "Bar";
}
diff --git a/src/main/cpp/system.cpp b/src/main/cpp/system.cpp
index 49c6be81..fa6a98c5 100644
--- a/src/main/cpp/system.cpp
+++ b/src/main/cpp/system.cpp
@@ -191,9 +191,10 @@ void System::addProgramFilePathComponents(Properties&
props)
FilesystemPath programPath(programFileName);
#if LOG4CXX_LOGCHAR_IS_WCHAR
auto root_name = programPath.root_name().wstring();
- props.setProperty(prefix + LOG4CXX_STR("ROOT_NAME"), root_name);
+ if (!root_name.empty())
+ props.setProperty(prefix + LOG4CXX_STR("ROOT_NAME"), root_name);
auto root_directory = programPath.root_directory().wstring();
- props.setProperty(LOG4CXX_STR("ROOT_DIRECTORY"),root_directory);
+ props.setProperty(prefix +
LOG4CXX_STR("ROOT_DIRECTORY"),root_directory);
auto root_path = programPath.root_path().wstring();
props.setProperty(prefix + LOG4CXX_STR("ROOT_PATH"), root_path);
auto relative_path = programPath.relative_path().wstring();
@@ -205,12 +206,14 @@ void System::addProgramFilePathComponents(Properties&
props)
auto stem = programPath.stem().wstring();
props.setProperty(prefix + LOG4CXX_STR("STEM"), stem);
auto extension = programPath.extension().wstring();
- props.setProperty(prefix + LOG4CXX_STR("EXTENSION"), extension);
+ if (!extension.empty())
+ props.setProperty(prefix + LOG4CXX_STR("EXTENSION"), extension);
#else
LOG4CXX_DECODE_CHAR(root_name, programPath.root_name().string());
- props.setProperty(prefix + LOG4CXX_STR("ROOT_NAME"), root_name);
+ if (!root_name.empty())
+ props.setProperty(prefix + LOG4CXX_STR("ROOT_NAME"), root_name);
LOG4CXX_DECODE_CHAR(root_directory,
programPath.root_directory().string());
- props.setProperty(LOG4CXX_STR("ROOT_DIRECTORY"),root_directory);
+ props.setProperty(prefix +
LOG4CXX_STR("ROOT_DIRECTORY"),root_directory);
LOG4CXX_DECODE_CHAR(root_path, programPath.root_path().string());
props.setProperty(prefix + LOG4CXX_STR("ROOT_PATH"), root_path);
LOG4CXX_DECODE_CHAR(relative_path,
programPath.relative_path().string());
@@ -222,7 +225,8 @@ void System::addProgramFilePathComponents(Properties& props)
LOG4CXX_DECODE_CHAR(stem, programPath.stem().string());
props.setProperty(prefix + LOG4CXX_STR("STEM"), stem);
LOG4CXX_DECODE_CHAR(extension, programPath.extension().string());
- props.setProperty(prefix + LOG4CXX_STR("EXTENSION"), extension);
+ if (!extension.empty())
+ props.setProperty(prefix + LOG4CXX_STR("EXTENSION"), extension);
#endif
#endif // LOG4CXX_HAS_FILESYSTEM_PATH
}
diff --git a/src/main/include/log4cxx/spi/configurator.h
b/src/main/include/log4cxx/spi/configurator.h
index 651a311d..de19844a 100644
--- a/src/main/include/log4cxx/spi/configurator.h
+++ b/src/main/include/log4cxx/spi/configurator.h
@@ -34,7 +34,7 @@ enum class ConfigurationStatus{
};
/**
-Implemented by classes capable of configuring log4j using a URL.
+An abstract base for classes capable of configuring Log4cxx.
*/
class LOG4CXX_EXPORT Configurator : virtual public helpers::Object
{
@@ -47,13 +47,12 @@ class LOG4CXX_EXPORT Configurator : virtual public
helpers::Object
#endif
/**
- Interpret a resource pointed by a URL and set up log4j
accordingly.
-
- The configuration is done relative to the <code>hierarchy</code>
- parameter.
+ Read configuration from \c configFileName.
+ If \c repository is not provided,
+ the spi::LoggerRepository held by LogManager is used.
@param configFileName The file to parse
- @param repository Where the Logger instances reside.
+ @param repository Holds the Logger instances.
*/
virtual ConfigurationStatus doConfigure
( const File& configFileName
diff --git a/src/site/markdown/configuration-samples.md
b/src/site/markdown/configuration-samples.md
index 76bd8edf..c1eb08e6 100644
--- a/src/site/markdown/configuration-samples.md
+++ b/src/site/markdown/configuration-samples.md
@@ -113,8 +113,8 @@ log4j.appender.A1.layout.ConversionPattern=%.30c - %Y%m%y%n
The following Log4cxx 1.6 configuration file uses
the variables added in the \ref com/foo/config4.cpp example
to store a log file per executable in a product related logs directory:
-- Windows, "C:\ProgramData\CompanyName\ProductName\Logs"
-- Non-Windows, "/var/local/companyName/productName/Logs"
+- Windows, "C:\Users\XXXXX\AppData\Local\companyName\productName\logs"
+- Non-Windows, "/var/local/companyName/productName/logs"
~~~{.properties}
# Uncomment a line to enable debugging for a category
@@ -123,7 +123,7 @@ log4j.rootCategory=INFO, A1
log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1.MaxFileSize=5MB
log4j.appender.A1.MaxBackupIndex=12
-log4j.appender.A1.File=${LocalAppData}/${CURRENT_VENDOR_FOLDER}/${CURRENT_PRODUCT_FOLDER}/Logs/${PROGRAM_FILE_PATH.STEM}.log
+log4j.appender.A1.File=${LocalAppData}/${CURRENT_VENDOR_FOLDER}/${CURRENT_PRODUCT_FOLDER}/logs/${PROGRAM_FILE_PATH.STEM}.log
log4j.appender.A1.Append=true
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%t]
%-5p %.30c - %m%n
@@ -133,7 +133,7 @@ log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%.30c - %Y%m%y%n
log4j.appender.csvData=org.apache.log4j.FileAppender
-log4j.appender.csvData.File=${LocalAppData}/${CURRENT_VENDOR_FOLDER}/${CURRENT_PRODUCT_FOLDER}/MessageData.csv
+log4j.appender.csvData.File=${LocalAppData}/${CURRENT_VENDOR_FOLDER}/${CURRENT_PRODUCT_FOLDER}/GraphableData.csv
log4j.appender.csvData.Append=false
log4j.appender.csvData.layout=org.apache.log4j.PatternLayout
log4j.appender.csvData.layout.ConversionPattern=%m,%d{yyyy-MM-dd,HH:mm,ss.SSS}%n
@@ -259,8 +259,8 @@ where the path uses the program vendor and product name.
The following Log4cxx 1.6 configuration file uses
the variables added in the \ref com/foo/config4.cpp example
to store a log file per executable in a product related logs directory:
-- Windows, "C:\ProgramData\CompanyName\ProductName\Logs"
-- Non-Windows, "/var/local/companyName/productName/Logs"
+- Windows, "C:\Users\XXXXX\AppData\Local\companyName\productName\logs"
+- Non-Windows, "/var/local/companyName/productName/logs"
~~~{.xml}
<?xml version="1.0" encoding="UTF-8" ?>
@@ -275,7 +275,7 @@ to store a log file per executable in a product related
logs directory:
</appender>
<appender name="FileAppender" class="org.apache.log4j.FileAppender">
- <param name="file"
value="${LocalAppData}/${CURRENT_VENDOR_FOLDER}/${CURRENT_PRODUCT_FOLDER}/Logs/${PROGRAM_FILE_PATH.STEM}.log"
/>
+ <param name="file"
value="${LocalAppData}/${CURRENT_VENDOR_FOLDER}/${CURRENT_PRODUCT_FOLDER}/logs/${PROGRAM_FILE_PATH.STEM}.log"
/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] %c
%-5p - %m%n" />
</layout>