使用 logback 关闭时是否需要刷新事件?
我们正在将多个 Web 应用程序从 log4j 迁移到 logback。在关闭我们的应用程序时,我们当前调用:
org.apache.log4j.LogManager.shutdown();
应该刷新所有异步日志记录并关闭所有外部资源(文件、套接字)。
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
从版本 1.1.10 开始,当 Web 应用程序停止或重新加载时,logback 负责停止当前的 logback-classic 上下文。
这是更新的文档: https://logback.qos.ch/manual/configuration.html #webShutdownHook
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
我不知道像 log4j 这样的整体管理器关闭,但当使用 ServletContextListener 销毁它们的上下文时,我会关闭所有单独的上下文记录器,如下所示:
此外, LoggerContext.stop() 是可用的,并且在内部执行一些相同的功能,但我不要使用它,所以我无法评论它是否比重置更好。
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.
似乎只需将
添加到配置中就应该停止上下文。来自logback 文档:
以及来自DelayingShutdownHook 摘要:
It seems that just adding
<shutdownHook/>
into configuration should stop the context.From logback docs:
And from DelayingShutdownHook summary:
这是一个简单的方法:
Here's a simple approach: