Re: Using the Log4j 1.2 bridge.

2024-02-10 Thread Gary Gregory
Thank you Piotr! I'll poke around...

Gary

On Sat, Feb 10, 2024, 5:24 PM Piotr P. Karwasz 
wrote:

> Hi Gary,
>
> On Sat, 10 Feb 2024 at 18:14, Gary Gregory  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
>


Re: Using the Log4j 1.2 bridge.

2024-02-10 Thread Piotr P. Karwasz
Hi Gary,

On Sat, 10 Feb 2024 at 18:14, Gary Gregory  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


Fwd: Using the Log4j 1.2 bridge.

2024-02-10 Thread Gary Gregory
Hi All and Piotr mostly (since you did the 2.x code in Commons Logging),

[ Background: My reply
https://lists.apache.org/thread/rcxkfffg9pfj9662d1fxlyo4l8cv2yyq to
the post https://lists.apache.org/thread/w5yq2locvdt8yhf8k9075vgjg1kw5569
]

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");
}

It turns out that I see this in the test resources, log4j2-test.xml:












I can understand that the above v2 file does not kick in before my
branch since the problematic test is a v1 test. But, now that this
test ends up using the 1.2-api bridge, the file is in play.

How do I make the 1.x test point to a different file so that the code
passes as is?

TY,
Gary