logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Ross (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-1821) (not only) default rollover strategy is *broken*
Date Thu, 23 Feb 2017 23:12:44 GMT

    [ https://issues.apache.org/jira/browse/LOG4J2-1821?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15881527#comment-15881527
] 

Michael Ross commented on LOG4J2-1821:
--------------------------------------

I am experiencing this exact same problem, where %i in the filePattern will only create one
rollover file (file.log and file.log.1) instead of the max number specified. The only workaround
I found is to add a dash in front of the %i (i.e. file-%i.log)

> (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


Mime
View raw message