如何强制执行回滚轮换 [英] How can I Force logback rotation

查看:97
本文介绍了如何强制执行回滚轮换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

理想情况下,注销"可以选择始终在应用程序启动时轮换.由于该功能不存在,如何在应用启动时强制重新登录?由于其供应商代码,我将不得不编写自己的程序RotateLB.java.我该如何使用供应商应用程序使用的相同logback.xml.当日志达到250MB时,它正在旋转.

Ideally Logback would have an option to always rotate on app startup. since that feature is absent, how can I force logback to rotate on app startup? Since its vendor code, I'll have to write my own program RotateLB.java. How can I do it yet use the same logback.xml the vendor app uses. It is doing rotate when log hits 250MB.

推荐答案

这可以通过编写自己的触发器,获取ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP并重载isTriggeringEvent()来完成.

This can be done by writing your own trigger, deriving ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP and overloading isTriggeringEvent().

但是您需要编辑logback.xml配置文件.

But you will need to edit the logback.xml config file.

如果不可能,则可以使用-Dlogback.configurationFile = ...指定备用配置文件.

If not possible, you can specify an alternate config file with -Dlogback.configurationFile=...

或者,由于您的应用程序可能正在使用SLF4J API,因此您可以尝试删除logback,而改用Log4j 2,它确实具有您所需的选项.

Or, since your app is probably using the SLF4J API, you could try to remove logback and use Log4j 2 instead, which does have the option you need.

这篇关于如何强制执行回滚轮换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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