Logback's documentation recommends stopping the context on shutdown to flush the loggers and let appenders terminate properly. https://logback.qos.ch/manual/appenders.html#AsyncAppender https://logback.qos.ch/manual/configuration.html#stopContext
This doesn't appear to be happening during LogbackLoggingSystem.cleanUp(). Is there perhaps a reason for Spring Boot not to call stop() on LoggerContext? Are the users expected to do this instead?
Comment From: wilkinsona
You can opt in for this by setting logging.register-shutdown-hook=true. Please see https://github.com/spring-projects/spring-boot/issues/4026 for some background. It looks like we need to do a better job of documenting that property. We can use this issue to do that.
Comment From: joca-bt
Thanks for the information. I was reading through the related tickets and they were very helpful.
It seems the logging system shutdown hook is run before ContextClosedEvent is sent and before the web server is terminated (when using graceful shutdown). This doesn't work for us since we still want logging to be there until just before the beginning of the bean destruction process. A lot of relevant logging may happen until this point (e.g. during web server graceful shutdown) and we need the logging system to be operational until there.
We will probably add a bean with the lowest precedence lifecycle (last one running) and close the logger context there, since it seems simple enough and will work for us. It might not be idiomatic but it will work.
Comment From: ThomHurks
I stumbled on this issue by accident and can definitely say that better documentation would be appreciated! We also use Logback in our application and if setting logging.register-shutdown-hook=true is a best practice in that case (or does it also have downsides?) then it would be very good to know as we currently don't have it set. It would also be useful to know why true is not the default when using Logback. Right now there isn't much information out there regarding this setting, besides comments in Spring Boot's issue tracker.