Avoid removing application-managed JUL bridge handler#50779
Open
dhruv-15-03 wants to merge 1 commit into
Open
Conversation
`LogbackLoggingSystem` and `Log4J2LoggingSystem` install a JUL bridge handler only when the application is not already managing `java.util.logging`. However, `cleanUp()` removed the bridge handler whenever the bridge class was present on the classpath, so Spring Boot uninstalled a bridge handler that an application had installed and managed itself. Track whether the bridge handler was installed by Spring Boot and only remove it during cleanup when that is the case. See spring-projectsgh-33697 Signed-off-by: dhruv-15-03 <dhruvrastogi2004@gmail.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 addresses the install/uninstall asymmetry described in #33697.
LogbackLoggingSystemandLog4J2LoggingSysteminstall a JUL bridge handler (SLF4JBridgeHandler/Log4jBridgeHandler) only when the application is not already managingjava.util.loggingitself (i.e. when the JUL root logger is using at most a singleConsoleHandler). However,cleanUp()removed the bridge handler whenever the bridge class was merely present on the classpath.As a result, when an application installs and manages its own JUL bridge handler, Spring Boot would still uninstall it during context shutdown — tearing down a handler it never installed.
This change tracks whether the bridge handler was installed by Spring Boot and only removes it during cleanup when that is the case, making install and uninstall symmetric.
A test is added to each logging system verifying that an application-installed bridge handler is left in place after
cleanUp(). Both tests fail without the corresponding production change.Note: this PR is scoped to the install/uninstall asymmetry. The separate question of when the bridge handler is removed during the context lifecycle (also discussed in the issue) is intentionally left out of scope.