The key is to close the logger context. One way is to invoke the following code before the JVM exits.
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
loggerContext.stop();
The <shutdownHook/> directive in configuration file adds a JVM shutdown hook which closes the logger context. Unfortunately, due to a bug in logback version 1.2.x, <shutdownHook/> directive requires a class name. It needs to be invoked as
<shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/>
The bug is corrected in logback version 1.3.x. Moreover, DelayingShutdownHook class was renamed as DefaultShutdownHook. This, in version 1.3.x, the previous directive needs to be written as
<shutdownHook class="ch.qos.logback.core.hook.DefaultShutdownHook"/>
or equivalently as
|