spring-projects / spring-projects/spring-boot
Slf4JBridgeHandler.uninstall called too early in context close, swallowing JUL log output.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 81.5k
- Forks
- 42.7k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 65
Description
Behavior
JUL logging output in @PreDestroy methods is swallowed, not logged.
Expected behavior
JUL logging output in @PreDestroy methods logged.
Description
LogbackLoggingSystem.cleanup() -> Slf4JLoggingSystem.cleanup() -> Slf4JBridgeHandler.uninstall()
is called before @PreDestroy methods.
therefore JUL logging in @PreDestroy is swallowed, not logged.
This is because the uninstall was registered as a SmartLifeCycle, in LoggingApplicationListener.onApplicationPreparedEvent.
And SmartLifeCycle.stop() is called early in the AbstractApplicationContext.doClose(), before the destroyBeans().
Versions
- spring-boot-2.6.13.jar / spring-boot-2.7.7.jar
- jul-to-slf4j-1.7.36.jar
Context
- WAR deployment
- Apache Tomcat Version 9.0.53
Misc
There are multiple call paths reaching LoggingApplicationListener.cleanupLoggingSystem(). Also one for onContextClosedEvent(). but this contains shortcut code for exactly this scenario. So it looks like the SmartLifeCycle shutdown route is intentional, but unclear to me why the shutdown of Slf4JBridgeHandler should happen so early in the shutdown.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing LoggingApplicationListener.cleanupLoggingSystem(), including its onApplicationPreparedEvent and onContextClosedEvent paths, then compare LogbackLoggingSystem.cleanup(), Slf4JLoggingSystem.cleanup(), and Slf4JBridgeHandler.uninstall() with AbstractApplicationContext.doClose() and destroyBeans(). Reproduce the WAR shutdown scenario with JUL logging in an @PreDestroy method; done means that output remains logged during context destruction without breaking the intended cleanup path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- backend, observability
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100