spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

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

Open sijskes opened this issue 2 years ago • 6 comments

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.

sijskes avatar Jan 05 '23 11:01 sijskes