使用logback关闭时是否需要刷新事件? [英] Do I need to flush events when shutting down using logback?

查看:411
本文介绍了使用logback关闭时是否需要刷新事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在从log4j迁移到几个Web应用程序的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).

在logback中是否存在类似的东西,或者在关机时是否会以某种方式自动刷新?

Is there something similar in logback or does it somehow flush automatically on shutdown?

Mike

推荐答案

似乎只需在配置中添加< shutdownHook /> 即可停止上下文。

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

来自 logback docs

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

来自 DelayingShutdownHook摘要


ShutdownHook实现在指定的延迟后停止Logback上下文。默认延迟为0 ms(零)。

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

这篇关于使用logback关闭时是否需要刷新事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆