apache / apache/logging-log4j2
Log4j 1.2 API initialization does not respect `log4j1.compatibility` setting
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 1.7k
- Avg merge
- 21h 30m
- Merged PRs (30d)
- 27
Description
## Description
I've come across a bug where a call to `org.apache.log4j.LogManager.getLogger()` exhibits apparently unintended side effects on the configuration (particularly log levels) of other loggers that were created previously. The below code prints two INFO-level log messages on Log4j 2.22.1 and earlier, but since 2.23.0 only the first message is emitted:
```java
Logger logger = (Logger) LogManager.getLogger(App.class);
TestAppender testAppender = new TestAppender();
logger.addAppender(testAppender);
logger.setLevel(Level.INFO);
testAppender.start();
logger.info("Initializing Log4j 1.2 API...");
org.apache.log4j.LogManager.getLogger("org.example.OtherClass");
logger.info("Log4j 1.2 API initialized.");
System.out.printf("Recorded %,d events (expected 2)%n", testAppender.getLogEvents());
```
## Configuration
**Version:** 2.23.0 and later
**JDK:** Corretto 17.0.15
## Logs
```
[0] ~/log4j-repro # ./run.sh
Testing 2.20.0
19:12:51.494 [main] INFO org.example.App - Initializing Log4j 1.2 API...
19:12:51.502 [main] INFO org.example.App - Log4j 1.2 API initialized.
Recorded 2 events (expected 2)
Testing 2.21.0
19:12:53.067 [main] INFO org.example.App - Initializing Log4j 1.2 API...
19:12:53.075 [main] INFO org.example.App - Log4j 1.2 API initialized.
Recorded 2 events (expected 2)
Testing 2.21.1
19:12:54.209 [main] INFO org.example.App - Initializing Log4j 1.2 API...
19:12:54.217 [main] INFO org.example.App - Log4j 1.2 API initialized.
Recorded 2 events (expected 2)
Testing 2.22.0
19:12:55.348 [main] INFO org.example.App - Initializing Log4j 1.2 API...
19:12:55.356 [main] INFO org.example.App - Log4j 1.2 API initialized.
Recorded 2 events (expected 2)
Testing 2.22.1
19:12:56.534 [main] INFO org.example.App - Initializing Log4j 1.2 API...
19:12:56.544 [main] INFO org.example.App - Log4j 1.2 API initialized.
Recorded 2 events (expected 2)
Testing 2.23.0
19:12:58.049 [main] INFO org.example.App - Initializing Log4j 1.2 API...
Recorded 1 events (expected 2)
Testing 2.23.1
19:12:59.140 [main] INFO org.example.App - Initializing Log4j 1.2 API...
Recorded 1 events (expected 2)
Testing 2.24.0
19:13:00.573 [main] INFO org.example.App - Initializing Log4j 1.2 API...
Recorded 1 events (expected 2)
Testing 2.24.1
19:13:01.686 [main] INFO org.example.App - Initializing Log4j 1.2 API...
Recorded 1 events (expected 2)
Testing 2.24.2
19:13:02.762 [main] INFO org.example.App - Initializing Log4j 1.2 API...
Recorded 1 events (expected 2)
Testing 2.24.2
19:13:03.657 [main] INFO org.example.App - Initializing Log4j 1.2 API...
Recorded 1 events (expected 2)
Testing 2.25.0-SNAPSHOT
2025-05-16T02:13:04.911900Z main INFO Initializing Log4j 1.2 API...Recorded 1 events (expected 2)
```
## Reproduction
I made a standalone reproducer [here](https://github.com/rschmitt/logging-log4j2/tree/log4j-1.2-init-bug-repro). The `run.sh` script will run it against the last dozen releases of Log4j2, including the 2.25.0-SNAPSHOT release in the local Maven repository (in other words, the bug appears to be present as of the latest commit on `2.x`).
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.