public final class FixedWindowRollingPolicy extends RollingPolicyBase
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.
activeFileName
Constructor and Description |
---|
FixedWindowRollingPolicy()
Constructs a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
activateOptions() |
int |
getMaxIndex()
Get index of oldest log file to be retained.
|
int |
getMinIndex()
Get index of most recent log file.
|
RolloverDescription |
initialize(String file,
boolean append)
Initialize the policy and return any initial actions for rolling file appender..
|
RolloverDescription |
rollover(String currentFileName)
Prepare for a rollover.
|
void |
setMaxIndex(int maxIndex)
Set index of oldest log file to be retained.
|
void |
setMinIndex(int minIndex)
Set index of most recent log file.
|
formatFileName, getActiveFileName, getDatePatternConverter, getFileNamePattern, getIntegerPatternConverter, parseFileNamePattern, setActiveFileName, setFileNamePattern
public FixedWindowRollingPolicy()
public void activateOptions()
activateOptions
in interface org.apache.log4j.spi.OptionHandler
activateOptions
in class RollingPolicyBase
public RolloverDescription initialize(String file, boolean append)
file
- current value of RollingFileAppender.getFile().append
- current value of RollingFileAppender.getAppend().public RolloverDescription rollover(String currentFileName)
currentFileName
- file name for current active log file.public int getMaxIndex()
public int getMinIndex()
public void setMaxIndex(int maxIndex)
maxIndex
- index of oldest log file to be retained.public void setMinIndex(int minIndex)
minIndex
- Index of most recent log file.Copyright © 2013 The Apache Software Foundation. Licensed under the Apache License, Version 2.0
Apache Extras for Apache log4j, Apache log4j and Apache are trademarks of the Apache Software Foundation.