You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Ralph Goers (JIRA)" <ji...@apache.org> on 2017/02/26 06:06:44 UTC

[jira] [Resolved] (LOG4J2-1821) (not only) default rollover strategy is *broken*

     [ https://issues.apache.org/jira/browse/LOG4J2-1821?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ralph Goers resolved LOG4J2-1821.
---------------------------------
    Resolution: Fixed

> (not only) default rollover strategy is *broken*
> ------------------------------------------------
>
>                 Key: LOG4J2-1821
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1821
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.8
>         Environment: Java 1.8
>            Reporter: Shlomi Hazan
>            Priority: Blocker
>              Labels: easyfix, easytest
>             Fix For: 2.8.1
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> A previously working <DefaultRolloverStrategy max="10" /> is broken on v2.8, while working against 2.7, as only one rollover file is available. here is a MCVE:
> =================================================
> log4j2.xml
> =================================================
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration monitorInterval="2" status="TRACE">
>   <Appenders>  
>     <RollingFile name="rollingFileSync" fileName="logs/rolling.log" filePattern="logs/rolling.log.%i.gz">
>       <PatternLayout pattern="%d %-5level %c{1.} - %msg%n" />
>       <SizeBasedTriggeringPolicy size="100 KB" />
>       <DefaultRolloverStrategy max="10" />
>     </RollingFile>
>     <Async name="rollingFileAsync" blocking="false">
>       <AppenderRef ref="rollingFileSync" />
>     </Async>    
>   </Appenders>
>   <Loggers>
>     <Root level="TRACE">
>       <AppenderRef ref="rollingFileAsync" />
>     </Root>
>   </Loggers>  
> </Configuration>
> =================================================
> code:
> public static void main(String[] args) {
> System.setProperty("log4j.configurationFile", "log4j2.xml");		
> 		final Logger logger = LogManager.getLogger(RollingFileWithXmlConfigurationTest.class);		
> 		int numRecords = 10 * 1000* 1000;
> for (int i = 0; i < numRecords; i++) {
> 			logger.log(Level.INFO, "The time is: " + System.nanoTime());
> 		}
> 	}
> =================================================
> Here is a lead fixing the MCVE:
> $ git diff
> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/AbstractRolloverStrategy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/AbstractRolloverStrategy.java
> index 7981c7cc0..35f3cb1fb 100644
> --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/AbstractRolloverStrategy.java
> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/AbstractRolloverStrategy.java
> @@ -105,7 +105,7 @@ public abstract class AbstractRolloverStrategy implements RolloverStrategy {
>          File file = new File(path);
>          File parent = file.getParentFile();
>          parent.mkdirs();
> -        if (!path.contains("--1")) {
> +        if (!path.contains("-1")) {
>              return eligibleFiles;
>          }
>          Path dir = parent.toPath();
> @@ -114,7 +114,7 @@ public abstract class AbstractRolloverStrategy implements RolloverStrategy {
>          if (suffixLength > 0) {
>              fileName = fileName.substring(0, fileName.length() - suffixLength) + ".*";
>          }
> -        String filePattern = fileName.replace("--1", "-(\\d+)");
> +        String filePattern = fileName.replace("-1", "(\\d+)");
>          Pattern pattern = Pattern.compile(filePattern);
>          try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org