Class DefaultRolloverStrategy

  extended by org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy
All Implemented Interfaces:

public class DefaultRolloverStrategy
extends Object
implements RolloverStrategy

When rolling over, DefaultRolloverStrategy renames files according to an algorithm as described below.

The DefaultRolloverStrategy is a combination of a time-based policy and a fixed-window policy. When the file name pattern contains a date format then the rollover time interval will be used to calculate the time to use in the file pattern. When the file pattern contains an integer replacement token one of the counting techniques will be used.

When the ascending attribute is set to true (the default) then the counter will be incremented and the current log file will be renamed to include the counter value. If the counter hits the maximum value then the oldest file, which will have the smallest counter, will be deleted, all other files will be renamed to have their counter decremented and then the current file will be renamed to have the maximum counter value. Note that with this counting strategy specifying a large maximum value may entirely avoid renaming files.

When the ascending attribute is false, then the "normal" fixed-window strategy will be used.

Let max and min represent the values of respectively the MaxIndex and MinIndex options. Let "foo.log" be the value of the ActiveFile option and "foo.%i.log" the value of FileNamePattern. Then, when rolling over, the file foo.max.log will be deleted, the file foo.max-1.log will be renamed as foo.max.log, the file foo.max-2.log renamed as foo.max-1.log, and so on, the file foo.min+1.log renamed as foo.min+2.log. Lastly, the active file foo.log will be renamed as foo.min.log and a new active file name foo.log will be created.

Given that this rollover algorithm requires as many file renaming operations as the window size, large window sizes are discouraged.

Field Summary
protected static org.apache.logging.log4j.Logger LOGGER
          Allow subclasses access to the status logger without creating another instance.
Constructor Summary
protected DefaultRolloverStrategy(int minIndex, int maxIndex, boolean useMax, int compressionLevel, StrSubstitutor subst)
          Constructs a new instance.
Method Summary
static DefaultRolloverStrategy createStrategy(String max, String min, String fileIndex, String compressionLevelStr, Configuration config)
          Create the DefaultRolloverStrategy.
 int getCompressionLevel()
 int getMaxIndex()
 int getMinIndex()
 RolloverDescription rollover(RollingFileManager manager)
          Perform the rollover.
 String toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Field Detail


protected static final org.apache.logging.log4j.Logger LOGGER
Allow subclasses access to the status logger without creating another instance.

Constructor Detail


protected DefaultRolloverStrategy(int minIndex,
                                  int maxIndex,
                                  boolean useMax,
                                  int compressionLevel,
                                  StrSubstitutor subst)
Constructs a new instance.

minIndex - The minimum index.
maxIndex - The maximum index.
Method Detail


public static DefaultRolloverStrategy createStrategy(@PluginAttribute(value="max")
                                                                   String max,
                                                                   String min,
                                                                   String fileIndex,
                                                                   String compressionLevelStr,
                                                                   Configuration config)
Create the DefaultRolloverStrategy.

max - The maximum number of files to keep.
min - The minimum number of files to keep.
fileIndex - If set to "max" (the default), files with a higher index will be newer than files with a smaller index. If set to "min", file renaming and the counter will follow the Fixed Window strategy.
compressionLevelStr - The compression level, 0 (less) through 9 (more); applies only to ZIP files.
config - The Configuration.
A DefaultRolloverStrategy.


public int getCompressionLevel()


public int getMaxIndex()


public int getMinIndex()


public RolloverDescription rollover(RollingFileManager manager)
                             throws SecurityException
Perform the rollover.

Specified by:
rollover in interface RolloverStrategy
manager - The RollingFileManager name for current active log file.
A RolloverDescription.
SecurityException - if an error occurs.


public String toString()
toString in class Object

Copyright © 1999-2015 Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.