Description
Log4j1ConfigurationConverter writes the resolved values of ${...} variables into the converted configuration,
instead of translating them.
The converter shares Log4j1ConfigurationParser with the runtime Log4j1ConfigurationFactory.
Log4j1ConfigurationParser.getProperty calls OptionConverter.substVars,
which resolves each variable first from PropertiesUtil (system properties and the other Log4j property sources)
and only then from the properties file itself.
At runtime this is the correct Log4j 1 behavior. For a conversion tool it is not:
- the output depends on the machine the converter runs on,
and captures its system properties (user names, paths, or anything else set with -D);
- the output loses the indirection:
${catalina.base}/logs/app.log becomes a fixed path
instead of ${sys:catalina.base}/logs/app.log.
Expected behavior: when converting, variables should be translated to the equivalent Log4j 2 lookup
(${sys:...}, or a <Property> for variables defined in the file) rather than resolved.
The runtime Log4j1ConfigurationFactory should keep its current semantics.
Configuration
Version: 2.26.1 (and 2.x at d631e82)
Operating system: any
JDK: any
Logs
None.
Reproduction
log4j.rootLogger=INFO, FILE
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=${user.home}/app.log
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
Converting this file with Log4j1ConfigurationConverter produces a fileName containing
the home directory of the user running the converter, instead of ${sys:user.home}/app.log.
Description
Log4j1ConfigurationConverterwrites the resolved values of${...}variables into the converted configuration,instead of translating them.
The converter shares
Log4j1ConfigurationParserwith the runtimeLog4j1ConfigurationFactory.Log4j1ConfigurationParser.getPropertycallsOptionConverter.substVars,which resolves each variable first from
PropertiesUtil(system properties and the other Log4j property sources)and only then from the properties file itself.
At runtime this is the correct Log4j 1 behavior. For a conversion tool it is not:
and captures its system properties (user names, paths, or anything else set with
-D);${catalina.base}/logs/app.logbecomes a fixed pathinstead of
${sys:catalina.base}/logs/app.log.Expected behavior: when converting, variables should be translated to the equivalent Log4j 2 lookup
(
${sys:...}, or a<Property>for variables defined in the file) rather than resolved.The runtime
Log4j1ConfigurationFactoryshould keep its current semantics.Configuration
Version: 2.26.1 (and
2.xatd631e82)Operating system: any
JDK: any
Logs
None.
Reproduction
Converting this file with
Log4j1ConfigurationConverterproduces afileNamecontainingthe home directory of the user running the converter, instead of
${sys:user.home}/app.log.