org.apache.logging.log4j.core.appender.rolling
Class DefaultRolloverStrategy

java.lang.Object
  extended by org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy
All Implemented Interfaces:
RolloverStrategy

public class DefaultRolloverStrategy
extends Object
implements RolloverStrategy

When rolling over, FixedWindowRollingPolicy renames files according to a fixed window algorithm as described below.

The ActiveFileName property, which is required, represents the name of the file where current logging output will be written. The FileNamePattern option represents the file name pattern for the archived (rolled over) log files. If present, the FileNamePattern option must include an integer token, that is the string "%i" somewhere within the pattern.

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. The current implementation will automatically reduce the window size to 12 when larger values are specified by the user.


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 min, int max, StrSubstitutor subst)
          Constructs a new instance.
 
Method Summary
static DefaultRolloverStrategy createStrategy(String max, String min, Configuration config)
          Create the DefaultRolloverStrategy.
 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

LOGGER

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

Constructor Detail

DefaultRolloverStrategy

protected DefaultRolloverStrategy(int min,
                                  int max,
                                  StrSubstitutor subst)
Constructs a new instance.

Parameters:
min - The minimum index.
max - The maximum index.
Method Detail

rollover

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

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

toString

public String toString()
Overrides:
toString in class Object

createStrategy

public static DefaultRolloverStrategy createStrategy(String max,
                                                     String min,
                                                     Configuration config)
Create the DefaultRolloverStrategy.

Parameters:
max - The maximum number of files to keep.
min - The minimum number of files to keep.
config - The Configuration.
Returns:
A DefaultRolloverStrategy.


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