[ https://issues.apache.org/jira/browse/LOG4J2-524?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13888459#comment-13888459 ]
Remko Popma commented on LOG4J2-524: ------------------------------------ I thought this might be a bug but it seems like everything works correctly. To clarify: the {{filePattern="app-%d\{yyyy-MM-dd}.%i.log"}} has two parts for rollover: a date part ({{yyyy-MM-dd}}) and an index part ({{%i}}). The date part is used by {{TimeBasedTriggeringPolicy}}. The index part is used by {{SizeBasedTriggeringPolicy}} *if one is configured*. If you configure both a SizeBased and a TimeBased triggering policy, then you can have multiple rollovers within the same time period. In that case, the {{<DefaultRolloverStrategy max="3"/>}} config will only keep the 3 most recent rolled over files _within the same time period_. For example, this config: {code} <RollingFile name="RollingFile" fileName="app.log" filePattern="app-%d{yyyy-MM-dd_HH-mm-ss}.%i.log"> <!-- roll over every second --> <PatternLayout> <Pattern>%d %p %c [%t] %m%n</Pattern> </PatternLayout> <Policies> <TimeBasedTriggeringPolicy interval="1" modulate="true"/> <SizeBasedTriggeringPolicy size="5 b"/> <!-- roll over if log file size exceeds 5 bytes --> </Policies> <DefaultRolloverStrategy compressionLevel="0" max="3"/> </RollingFile> {code} With this test program: {code} Logger logger = LogManager.getLogger(); for (int i = 0; i < 10; i++) { Thread.sleep(100); logger.info("test " + i); } {code} Gives this output: {code} app-2014-02-01_14-07-41.1.log app-2014-02-01_14-07-41.2.log app-2014-02-01_14-07-41.3.log app-2014-02-01_14-07-42.1.log app-2014-02-01_14-07-42.2.log app-2014-02-01_14-07-42.3.log app.log {code} The logic for removing old rolled-over log files is based on the file name, and a file is only removed if a renaming action would result in a file name that already exists. If you only have TimeBasedTriggeringPolicy, the renaming action always results in a file name that does not exist yet, so older files are never removed. > Rollover does not delete older archives > --------------------------------------- > > Key: LOG4J2-524 > URL: https://issues.apache.org/jira/browse/LOG4J2-524 > Project: Log4j 2 > Issue Type: Bug > Components: Appenders > Affects Versions: 2.0-beta9 > Reporter: Remko Popma > Fix For: 2.0-beta9 > > > This issue was raised by Kireet on the log4j-user mailing list: > I am trying to use the rolling file appender in log4j2, basically I want to > roll at midnight daily and keep 3 old log files. New files are created > properly, but log4j doesn't seem to be cleaning up the old files. Does log4j > only support cleanup of files within the time period? Here is the relevant > portion of the config. I tried things with and without the %i pattern. > {code} > <RollingFile name="Event" fileName="app.log" > filePattern="app-%d{yyyy-MM-dd}.%i.log"> > <PatternLayout> > <Pattern>%m%n</Pattern> > </PatternLayout> > <Policies> > <TimeBasedTriggeringPolicy interval="1" modulate="true"/> > </Policies> > <DefaultRolloverStrategy compressionLevel="0" max="3"/> > </RollingFile> > {code} -- This message was sent by Atlassian JIRA (v6.1.5#6160) --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-dev-h...@logging.apache.org