Skip to content

Commit 561657e

Browse files
authored
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
1 parent 9b2fcf6 commit 561657e

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

src/examples/cpp/com/foo/product_version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
std::string getVendorFolder()
1919
{
20-
return "ApacheSoftwareFoundation";
20+
return "Foo";
2121
}
2222
std::string getProductFolder()
2323
{
24-
return "Logging";
24+
return "Bar";
2525
}

src/main/cpp/system.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,10 @@ void System::addProgramFilePathComponents(Properties& props)
191191
FilesystemPath programPath(programFileName);
192192
#if LOG4CXX_LOGCHAR_IS_WCHAR
193193
auto root_name = programPath.root_name().wstring();
194-
props.setProperty(prefix + LOG4CXX_STR("ROOT_NAME"), root_name);
194+
if (!root_name.empty())
195+
props.setProperty(prefix + LOG4CXX_STR("ROOT_NAME"), root_name);
195196
auto root_directory = programPath.root_directory().wstring();
196-
props.setProperty(LOG4CXX_STR("ROOT_DIRECTORY"),root_directory);
197+
props.setProperty(prefix + LOG4CXX_STR("ROOT_DIRECTORY"),root_directory);
197198
auto root_path = programPath.root_path().wstring();
198199
props.setProperty(prefix + LOG4CXX_STR("ROOT_PATH"), root_path);
199200
auto relative_path = programPath.relative_path().wstring();
@@ -205,12 +206,14 @@ void System::addProgramFilePathComponents(Properties& props)
205206
auto stem = programPath.stem().wstring();
206207
props.setProperty(prefix + LOG4CXX_STR("STEM"), stem);
207208
auto extension = programPath.extension().wstring();
208-
props.setProperty(prefix + LOG4CXX_STR("EXTENSION"), extension);
209+
if (!extension.empty())
210+
props.setProperty(prefix + LOG4CXX_STR("EXTENSION"), extension);
209211
#else
210212
LOG4CXX_DECODE_CHAR(root_name, programPath.root_name().string());
211-
props.setProperty(prefix + LOG4CXX_STR("ROOT_NAME"), root_name);
213+
if (!root_name.empty())
214+
props.setProperty(prefix + LOG4CXX_STR("ROOT_NAME"), root_name);
212215
LOG4CXX_DECODE_CHAR(root_directory, programPath.root_directory().string());
213-
props.setProperty(LOG4CXX_STR("ROOT_DIRECTORY"),root_directory);
216+
props.setProperty(prefix + LOG4CXX_STR("ROOT_DIRECTORY"),root_directory);
214217
LOG4CXX_DECODE_CHAR(root_path, programPath.root_path().string());
215218
props.setProperty(prefix + LOG4CXX_STR("ROOT_PATH"), root_path);
216219
LOG4CXX_DECODE_CHAR(relative_path, programPath.relative_path().string());
@@ -222,7 +225,8 @@ void System::addProgramFilePathComponents(Properties& props)
222225
LOG4CXX_DECODE_CHAR(stem, programPath.stem().string());
223226
props.setProperty(prefix + LOG4CXX_STR("STEM"), stem);
224227
LOG4CXX_DECODE_CHAR(extension, programPath.extension().string());
225-
props.setProperty(prefix + LOG4CXX_STR("EXTENSION"), extension);
228+
if (!extension.empty())
229+
props.setProperty(prefix + LOG4CXX_STR("EXTENSION"), extension);
226230
#endif
227231
#endif // LOG4CXX_HAS_FILESYSTEM_PATH
228232
}

src/main/include/log4cxx/spi/configurator.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ enum class ConfigurationStatus{
3434
};
3535

3636
/**
37-
Implemented by classes capable of configuring log4j using a URL.
37+
An abstract base for classes capable of configuring Log4cxx.
3838
*/
3939
class LOG4CXX_EXPORT Configurator : virtual public helpers::Object
4040
{
@@ -47,13 +47,12 @@ class LOG4CXX_EXPORT Configurator : virtual public helpers::Object
4747
#endif
4848

4949
/**
50-
Interpret a resource pointed by a URL and set up log4j accordingly.
51-
52-
The configuration is done relative to the <code>hierarchy</code>
53-
parameter.
50+
Read configuration from \c configFileName.
51+
If \c repository is not provided,
52+
the spi::LoggerRepository held by LogManager is used.
5453
5554
@param configFileName The file to parse
56-
@param repository Where the Logger instances reside.
55+
@param repository Holds the Logger instances.
5756
*/
5857
virtual ConfigurationStatus doConfigure
5958
( const File& configFileName

src/site/markdown/configuration-samples.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ log4j.appender.A1.layout.ConversionPattern=%.30c - %Y%m%y%n
113113
The following Log4cxx 1.6 configuration file uses
114114
the variables added in the \ref com/foo/config4.cpp example
115115
to store a log file per executable in a product related logs directory:
116-
- Windows, "C:\ProgramData\CompanyName\ProductName\Logs"
117-
- Non-Windows, "/var/local/companyName/productName/Logs"
116+
- Windows, "C:\Users\XXXXX\AppData\Local\companyName\productName\logs"
117+
- Non-Windows, "/var/local/companyName/productName/logs"
118118

119119
~~~{.properties}
120120
# Uncomment a line to enable debugging for a category
@@ -123,7 +123,7 @@ log4j.rootCategory=INFO, A1
123123
log4j.appender.A1=org.apache.log4j.RollingFileAppender
124124
log4j.appender.A1.MaxFileSize=5MB
125125
log4j.appender.A1.MaxBackupIndex=12
126-
log4j.appender.A1.File=${LocalAppData}/${CURRENT_VENDOR_FOLDER}/${CURRENT_PRODUCT_FOLDER}/Logs/${PROGRAM_FILE_PATH.STEM}.log
126+
log4j.appender.A1.File=${LocalAppData}/${CURRENT_VENDOR_FOLDER}/${CURRENT_PRODUCT_FOLDER}/logs/${PROGRAM_FILE_PATH.STEM}.log
127127
log4j.appender.A1.Append=true
128128
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
129129
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
133133
log4j.appender.console.layout.ConversionPattern=%.30c - %Y%m%y%n
134134
135135
log4j.appender.csvData=org.apache.log4j.FileAppender
136-
log4j.appender.csvData.File=${LocalAppData}/${CURRENT_VENDOR_FOLDER}/${CURRENT_PRODUCT_FOLDER}/MessageData.csv
136+
log4j.appender.csvData.File=${LocalAppData}/${CURRENT_VENDOR_FOLDER}/${CURRENT_PRODUCT_FOLDER}/GraphableData.csv
137137
log4j.appender.csvData.Append=false
138138
log4j.appender.csvData.layout=org.apache.log4j.PatternLayout
139139
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.
259259
The following Log4cxx 1.6 configuration file uses
260260
the variables added in the \ref com/foo/config4.cpp example
261261
to store a log file per executable in a product related logs directory:
262-
- Windows, "C:\ProgramData\CompanyName\ProductName\Logs"
263-
- Non-Windows, "/var/local/companyName/productName/Logs"
262+
- Windows, "C:\Users\XXXXX\AppData\Local\companyName\productName\logs"
263+
- Non-Windows, "/var/local/companyName/productName/logs"
264264

265265
~~~{.xml}
266266
<?xml version="1.0" encoding="UTF-8" ?>
@@ -275,7 +275,7 @@ to store a log file per executable in a product related logs directory:
275275
</appender>
276276
277277
<appender name="FileAppender" class="org.apache.log4j.FileAppender">
278-
<param name="file" value="${LocalAppData}/${CURRENT_VENDOR_FOLDER}/${CURRENT_PRODUCT_FOLDER}/Logs/${PROGRAM_FILE_PATH.STEM}.log" />
278+
<param name="file" value="${LocalAppData}/${CURRENT_VENDOR_FOLDER}/${CURRENT_PRODUCT_FOLDER}/logs/${PROGRAM_FILE_PATH.STEM}.log" />
279279
<layout class="org.apache.log4j.PatternLayout">
280280
<param name="ConversionPattern" value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] %c %-5p - %m%n" />
281281
</layout>

0 commit comments

Comments
 (0)