mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-22 17:35:22 +00:00
Streamline and harden `Log4J2LoggingSystem` by delegating more
functionality. The commit makes updates in two key areas:
Previously, each method fetched the `LoggerContext` directly from
`LogManager` and cast it to `....core.LoggerContext`. This approach
has several issues:
* ClassCastException risks:
- When Log4j Core is on the classpath but not the active implementation
(e.g. when `log4j-to-slf4j` is used).
- During shutdown, when `LogManager` may return a `SimpleLoggerContext`
(see spring-projects/spring-boot#26953).
* Unexpected reinitialization:
- If the logger context had already been stopped, `Log4J2LoggingSystem`
would trigger creation of a new context, even mid-shutdown.
Configuration file detection was previously hardcoded in
`Log4J2LoggingSystem`, which limited flexibility:
* Harder to support additional configuration formats.
* Coupled Spring Boot to internal Log4j Core classes such as
`AuthorizationProvider`.
This change now delegates configuration resolution to Log4j. This reduces
reliance on internal APIs and allows Log4j Core to handle configuration
formats and factories more naturally.
Signed-off-by: Piotr P. Karwasz <piotr@github.copernik.eu>
See gh-47424