[ https://issues.apache.org/jira/browse/LOG4J2-3490?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17544141#comment-17544141 ]
ASF subversion and git services commented on LOG4J2-3490: --------------------------------------------------------- Commit 1ab0788f61e6d396afc27c28e0cd9063deaa6e13 in logging-log4j2's branch refs/heads/release-2.x from Ralph Goers [ https://gitbox.apache.org/repos/asf?p=logging-log4j2.git;h=1ab0788f61 ] LOG4J2-3490 - The DirectWriteRolloverStrategy was not detecting the correct index to use during startup > Inconsistent counting in DirectWriteRolloverStrategy > ---------------------------------------------------- > > Key: LOG4J2-3490 > URL: https://issues.apache.org/jira/browse/LOG4J2-3490 > Project: Log4j 2 > Issue Type: Bug > Components: Appenders > Affects Versions: 2.17.2 > Reporter: Hans > Assignee: Ralph Goers > Priority: Major > > When several log files already exist, DirectWriteRolloverStrategy has an > inconsistent counting after restart. E.g. if maxFiles = 2 and in the log > folder there are two files app-21.log app-22.log, then the first created > file is app-2.log. > After a rollover, the next created file name is OK. > Example configuration > {code:java} > <?xml version="1.0" encoding="UTF-8"?> > <Configuration status="warn" name="MyApp" packages=""> > <Appenders> > <RollingFile name="RollingFile" > filePattern="logs/app-%i.log"> > <PatternLayout> > <Pattern>%d %p %c{1.} [%t] %m%n</Pattern> > </PatternLayout> > <Policies> > <SizeBasedTriggeringPolicy size="1 kB" /> > </Policies> > <DirectWriteRolloverStrategy maxFiles="2" /> > </RollingFile> > </Appenders> > <Loggers> > <Root level="INFO"> > <AppenderRef ref="RollingFile" /> > </Root> > </Loggers> > </Configuration> {code} > Just run following Java application several times and you will encounter the > effect after building up a log file history. > {code:java} > package log4jtest; > import org.apache.logging.log4j.LogManager; > import org.apache.logging.log4j.Logger; > public class LogTest > { > private static final Logger logger = LogManager.getLogger("HelloWorld"); > public static void main(String[] args) { > for (int i = 0; i < 15; i++) { > logger.info("Hello, World!"); > } > } > } > {code} > May be caused by line 317 of DirectWriteRolloverStrategy > {code:java} > final int fileIndex = eligibleFiles.size() > 0 ? (nextIndex > 0 ? nextIndex : > eligibleFiles.size()) : 1; > {code} > which defaults to the number of files when nextIndex is not initialized. > > > {panel:title=Running test application 5 times} > C:\misc\pt1\ws\log4jtest\logs>ls > app-1.log > C:\misc\pt1\ws\log4jtest\logs>ls > app-1.log app-2.log > C:\misc\pt1\ws\log4jtest\logs>ls > app-2.log app-3.log > C:\misc\pt1\ws\log4jtest\logs>ls > app-3.log app-4.log > C:\misc\pt1\ws\log4jtest\logs>ls > _*app-2.log*_ app-3.log app-4.log > {panel} > > -- This message was sent by Atlassian Jira (v8.20.7#820007)