Skip to content

Log4j 1 XML configuration creates appenders that no logger references #4516

Open

Description

@ppkarwasz

The Log4j 1 bridge's XmlConfiguration creates every top-level <appender> element, whether or not a logger references it. This has been the case since the bridge was added in 57bfd48 (LOG4J2-63). Log4j 1 did not do this: DOMConfigurator.parse explicitly skips <appender> elements and creates an appender only when an <appender-ref> points to it. The bridge's PropertiesConfiguration also only creates appenders by reference, like Log4j 1's PropertyConfigurator.

Consequences

  • Unused appenders still run: an appender that no logger references is still created and started. For example, a FileAppender creates its file and a SocketAppender opens its connection, which Log4j 1 never did for the same configuration.
  • Unused appenders still report errors: an unreferenced appender whose class cannot be loaded logs errors. Log4j 1 ignored it. Before fix: null-check parseAppender result in log4j-1.2-api XmlConfiguration #4172 it was worse: such an appender caused an NPE that discarded the whole configuration.
  • Unnamed appenders get registered: an <appender> without a name attribute is registered under the name "". The DTD requires name, and Log4j 1 could never create such an appender, because no <appender-ref> can point to it.

Proposed fix

Create appenders only by reference, like PropertiesConfiguration:

  1. In findAppenderByName, register a newly created appender with addAppender(AppenderAdapter.adapt(appender)). This is needed because parseChildrenOfLoggerElement looks the appender up through getAppender(refName).
  2. In doConfigure, ignore top-level <appender> elements, as DOMConfigurator does.

This also makes the guards added in #4172 unnecessary.

Tests

  • An unreferenced appender with a valid class is not present in the Configuration.
  • An unreferenced appender with a class that cannot be loaded produces no error.
  • A referenced appender still works, whether its <appender> element comes before or after the logger that references it.

Compatibility

Users who relied on unreferenced appenders being created would lose them. For example, they may look an appender up through Configuration.getAppender(name), or reference it from Log4j 2 code. That only worked by accident and never worked in Log4j 1, so I would target 2.x (the next minor release) rather than a patch release.

Activity

  1. added
    port-done
    on Nov 22, 2026
  2. added
    configuration
    on Nov 24, 2026
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

    configurationlegacy-1.2-bridgeport-done

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions