Log4j Rollingpolicy和MaxbackupIndex [英] Log4j Rollingpolicy and MaxbackupIndex

查看:86
本文介绍了Log4j Rollingpolicy和MaxbackupIndex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Am使用下面的代码每一分钟都对日志进行滚动,并且效果很好.

Am using the following code to rollover logs each and every minute and it works perfectly.

log4j.appender.AllFlows=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.AllFlows.rollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicy
log4j.appender.AllFlows.rollingPolicy.File=E:/Logs/AllFlows.log 
log4j.appender.AllFlows.rollingPolicy.FileNamePattern=E:/Logs/AllFlows.log.%d{yyyy-MM-dd-HH-mm}
log4j.appender.AllFlows.MaxBackupIndex=10
log4j.appender.AllFlows.layout=org.apache.log4j.PatternLayout
log4j.appender.AllFlows.layout.ConversionPattern=%d %-5p %x - %m%n

但是我只是想知道,它们有什么替代MaxbackupIndex的功能,因为当我使用TimebasedRollingPolicy时,它不能按预期工作吗?

However i just want to know , are they any alternatives for MaxbackupIndex as this is not working as expected when i use TimebasedRollingPolicy?

Am使用log41.2.17和apache log4j Extras

Am using log41.2.17 and apache log4j extras

推荐答案

不幸的是,使用log4j的标准API甚至使用Extras都无法实现.

Unfortunately, this is not possible using the standard API of log4j or even with the Extras.

但是,您可以使用类 org.apache.log4j.DailyMaxRollingFileAppender 1 ,例如:

However, you can use the class org.apache.log4j.DailyMaxRollingFileAppender 1, e.g.:

log4j.appender.AllFlows=org.apache.log4j.DailyMaxRollingFileAppender
log4j.appender.AllFlows.File=E:/Logs/AllFlows.log 
log4j.appender.AllFlows.MaxBackupIndex=10
log4j.appender.AllFlows.DatePattern='.'yyyy-MM-dd-HH-mm
log4j.appender.AllFlows.layout=org.apache.log4j.PatternLayout  
log4j.appender.AllFlows.layout.ConversionPattern=%d %-5p %x - %m%n


注释

  1. 带有MaxBackupIndex的自定义DailyRollingFileAppender 中查看此类的代码. .

这篇关于Log4j Rollingpolicy和MaxbackupIndex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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