Define logback shutdown hook in Spring Boot -
i using asyncappender in spring-boot (1.5.3.release) application.
logback.xml
<appender name="file_async" class="ch.qos.logback.classic.asyncappender"> <queuesize>5000</queuesize> <discardingthreshold>0</discardingthreshold> <appender-ref ref="file" /> </appender> as per logback documentation,
upon application shutdown or redeploy, asyncappender must stopped in order stop , reclaim worker thread , flush logging events queue.
https://logback.qos.ch/manual/appenders.html
further says:
in order avoid interrupting worker thread under these conditions, shutdown hook can inserted jvm runtime stops loggercontext after jvm shutdown has been initiated
i want know how stop asyncappender in spring boot application. @ place in spring boot, should define shutdown hook?
just add <shutdownhook/> instruction logback.xml. example:
<?xml version="1.0" encoding="utf-8"?> <configuration> <shutdownhook class="ch.qos.logback.core.hook.delayingshutdownhook"/> <appender name="file_async" class="ch.qos.logback.classic.asyncappender"> <queuesize>5000</queuesize> <discardingthreshold>0</discardingthreshold> <appender-ref ref="file" /> </appender> <!-- rest of logback config --> </configuration> with in place you'll notice following log message emitted when logback configuring itself:
info in ch.qos.logback.core.joran.action.shutdownhookaction - instantiate shutdown hook of type [ch.qos.logback.core.hook.delayingshutdownhook]
Comments
Post a Comment