Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
This change leverages the major Spring Boot version bump to streamline and harden
Log4J2LoggingSystem
in two key areas:1. Association with
LoggerContext
Previously, each method fetched the
LoggerContext
directly fromLogManager
and cast it too.a.l.l.core.LoggerContext
. This approach introduced several issues:ClassCastException
risks:log4j-to-slf4j
is used).LogManager
may return aSimpleLoggerContext
(see SpringApplicationShutdownHook throws ClassCastException when use log4j2 #26953).Unexpected reinitialization: If the logger context had already been stopped,
Log4J2LoggingSystem
would trigger creation of a new context, even mid-shutdown.2. Configuration format detection
Configuration file detection was previously hardcoded in
Log4J2LoggingSystem
, which limited flexibility:AuthorizationProvider
.This change now delegates configuration resolution to Log4j Core via:
ConfigurationFactory.getConfiguration(LoggerContext, String, URI, ClassLoader)
This reduces reliance on internal APIs and allows Log4j Core to handle configuration formats and factories more naturally.
Summary
Notes
loadConfiguration
methods to enable further refactorings in Spring Boot 4.1.x. For example, once Add getConfiguration method for multiple URIs apache/logging-log4j2#3921 is included in Log4j2.26.0
, configuration merging could also be delegated to Log4j Core, further reducing Spring Boot’s dependency surface on internal Log4j Core APIs.