spring-projects / spring-projects/spring-boot

Slf4JBridgeHandler.uninstall called too early in context close, swallowing JUL log output.

Open
#33,697 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.