Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to flush events when shutting down using logback?

Tags:

java

logback

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

like image 284
Mike Schall Avatar asked Sep 09 '10 16:09

Mike Schall


1 Answers

It seems that just adding <shutdownHook/> into configuration should stop the context.

From logback docs:

<configuration>
   <!-- in the absence of the class attribute, assume 
   ch.qos.logback.core.hook.DelayingShutdownHook -->
   <shutdownHook/>
  .... 
</configuration>

And from DelayingShutdownHook summary:

ShutdownHook implementation that stops the Logback context after a specified delay. The default delay is 0 ms (zero).

like image 155
Sasha Avatar answered Sep 21 '22 18:09

Sasha