log4j-extras MaxBackupIndex or similar
Asked Answered
F

1

6

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?

Ferric answered 30/5, 2014 at 0:50 Comment(0)
S
0

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>

Hope that helps you

Sailor answered 18/10, 2015 at 9:10 Comment(1)
This looks like a log4j 2.X configuration, not a 1.2.X, so I don't think it will answer the question.Clackmannan

© 2022 - 2024 — McMap. All rights reserved.