log4j-extras MaxBackupIndex或类似的 [英] log4j-extras MaxBackupIndex or similar

查看:146
本文介绍了log4j-extras MaxBackupIndex或类似的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用log4j-extras(1.2.17)org.apache.log4j.rolling.RollingFileAppender和每天滚动的org.apache.log4j.rolling.TimeBasedRollingPolicy. log4j的org.apache.log4j.RollingFileAppender中是否有与maxBackupIndex类似的属性(请注意程序包的区别)以限制归档文件的数量?如果没有,是否还有另一种每日限制文件滚动的替代方法?

I'm using log4j-extras (1.2.17) org.apache.log4j.rolling.RollingFileAppender with a org.apache.log4j.rolling.TimeBasedRollingPolicy that rolls daily. Is there a similar property to maxBackupIndex in log4j's org.apache.log4j.RollingFileAppender (note the package difference) to limit the number of archived files? If not, is there another alternative for daily rolling with limited files?

推荐答案

如果要限制log4j创建的文件数,请使用DefaultRolloverStrategy并将最大值"设置为要存储的文件数.但是在生成新日志时,较旧的文件将被删除.

If you want to limit the number of file created by log4j then use the DefaultRolloverStrategy and set the Max to the number of files you want to store. But on the generation of new logs the older files will be deleted.

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="MyApp" packages="">
<Appenders>
  <RollingFile name="RollingFile" fileName="logs/app.log"
             filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">
  <PatternLayout>
    <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
  </PatternLayout>
  <Policies>
    <TimeBasedTriggeringPolicy />
    <SizeBasedTriggeringPolicy size="250 MB"/>
  </Policies>
  <DefaultRolloverStrategy max="20"/>
</RollingFile>
</Appenders>
 <Loggers>
   <Root level="error">
     <AppenderRef ref="RollingFile"/>
   </Root>
 </Loggers>
</Configuration>

希望对您有帮助

这篇关于log4j-extras MaxBackupIndex或类似的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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