Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document logging.register-shutdown-hook and why you may want to enable it #24507

Closed
joca-bt opened this issue Dec 15, 2020 · 3 comments
Closed

Document logging.register-shutdown-hook and why you may want to enable it #24507

joca-bt opened this issue Dec 15, 2020 · 3 comments

Comments

@joca-bt
Copy link
Contributor

@joca-bt joca-bt commented Dec 15, 2020

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?

@wilkinsona
Copy link
Member

@wilkinsona wilkinsona commented Dec 15, 2020

You can opt in for this by setting logging.register-shutdown-hook=true. Please see #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.

@wilkinsona wilkinsona added this to the 2.3.x milestone Dec 15, 2020
@wilkinsona wilkinsona changed the title Consider calling stop on Logback's context on shutdown Document logging.register-shutdown-hook and why you may want to enable it Dec 15, 2020
@joca-bt
Copy link
Contributor Author

@joca-bt joca-bt commented Dec 15, 2020

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.

@ThomHurks
Copy link

@ThomHurks ThomHurks commented Dec 15, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants