Hi Gary,

On Sat, 10 Feb 2024 at 18:14, Gary Gregory <garydgreg...@gmail.com> wrote:
> In my branch 
> https://github.com/garydgregory/commons-logging/tree/log4j1-log42-api
> I have test failures where all 6 events are logged instead of 4 by the
> existing test that calls (mvn clean verify): Unexpected number of log
> events expected:<4> but was:<6> based on:
>
>     private void logPlainMessages(final Log log) {
>         log.trace("trace"); // Should not actually get logged
>         log.debug("debug"); // Should not actually get logged
>         log.info("info");
>         log.warn("warn");
>         log.error("error");
>         log.fatal("fatal");
>     }

Before the test is executed, Log4j 2.x is configured through the Log4j
1.x interface.

public void setUpTestAppender(final List logEvents) {
    final TestAppender appender = new TestAppender(logEvents);
    final Logger rootLogger = Logger.getRootLogger();
    rootLogger.removeAllAppenders();
    rootLogger.addAppender(appender);
    rootLogger.setLevel(Level.INFO);
}

The problem is in the `rootLogger.setLevel` call, which delegates to
`core.Logger#setLevel`.

The last one is broken: it modifies the `PrivateConfig` of the logger,
but does not modify the underlying `LoggerConfig`.
Therefore the level change does not propagate to the whole hierarchy.

I will be preparing version 2.23.0. Feel free to fix the bug or submit a PR.

Piotr

Reply via email to