ppkarwasz opened a new issue, #4516: URL: https://github.com/apache/logging-log4j2/issues/4516
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 57bfd4851c (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 #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. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
