We are migrating to logback from log4j for several web apps. In the shutdown of our application we currently call:
org.apache.log4j.LogManager.shutdown();
Which is supposed to flush all async logging and close all external resources (files, sockets).
Is there something similar in logback or does it somehow flush automatically on shutdown?
Mike
I'm not aware of an overall manager shutdown like log4j's but I close all my individual context loggers when their context is destroyed using a ServletContextListener like so:
Also, LoggerContext.stop() is svailable and does some of the same functions internally but I don't use it, so I can't comment on whether its better than reset or not.
It seems that just adding
<shutdownHook/>
into configuration should stop the context.From logback docs:
And from DelayingShutdownHook summary:
Here's a simple approach:
Version 1.1.10 onwards, logback takes care of stopping the current logback-classic context when the web-app is stopped or reloaded.
Here's the updated doc: https://logback.qos.ch/manual/configuration.html#webShutdownHook