Skip to content

Log4j1ConfigurationConverter writes resolved system properties instead of lookups #4348

Description

@ppkarwasz

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions