apache / apache/logging-log4j2
Log4j2EventListener's @ConditionalOnProperty has no effect - the listener always runs
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 1.7k
- Avg merge
- 21h 30m
- Merged PRs (30d)
- 27
Description
## Description
`Log4j2EventListener` carries `@ConditionalOnProperty("spring.cloud.config.watch.enabled")` but always runs.
It is registered twice:
- as `@Component` — the condition applies
- in `META-INF/spring.factories` (line 17) as an `ApplicationListener` — the condition **cannot** apply, because `SpringApplication` instantiates these directly, with no bean definition to suppress
So `spring.cloud.config.watch.enabled=false` disables nothing.
**Version:** 2.x `04c93c1d33` · JDK 21 · Spring Boot 3.4.3
## Logs
Property set to `false`, `monitorInterval` 300s:
```
RELOADED - the refresh event drove the reload, 298 seconds before
the monitorInterval would have
```
298s ahead of the interval, so the event drove it, not the timer.
## Reproduction
Run with `-Dspring.cloud.config.watch.enabled=false` and publish an `EnvironmentChangeEvent` (POST `/actuator/refresh`). Log4j reconfigures anyway.
## Suggested fix
Check the property inside `onApplicationEvent` against the `Environment` — smallest change, keeps the documented switch meaningful. Or drop `@ConditionalOnProperty` so the source stops promising a switch that does not exist.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating Log4j2EventListener and its registration in META-INF/spring.factories at line 17, then inspect onApplicationEvent. Reproduce with spring.cloud.config.watch.enabled=false and an EnvironmentChangeEvent from POST /actuator/refresh. Done means the listener does not reconfigure Log4j when the property is false.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100