Class DirectWriteRolloverStrategy
- java.lang.Object
-
- org.apache.logging.log4j.core.appender.rolling.AbstractRolloverStrategy
-
- org.apache.logging.log4j.core.appender.rolling.DirectWriteRolloverStrategy
-
- All Implemented Interfaces:
DirectFileRolloverStrategy
,RolloverStrategy
@Plugin(name="DirectWriteRolloverStrategy", category="Core", printObject=true) public class DirectWriteRolloverStrategy extends AbstractRolloverStrategy implements DirectFileRolloverStrategy
When rolling over,DirectWriteRolloverStrategy
writes directly to the file as resolved by the file pattern. Files will be renamed files according to an algorithm as described below.The DirectWriteRolloverStrategy uses similar logic as DefaultRolloverStrategy to determine the file name based on the file pattern, however the DirectWriteRolloverStrategy writes directly to a file and does not rename it during rollover, except if it is compressed, in which case it will add the appropriate file extension.
- Since:
- 2.8
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DirectWriteRolloverStrategy.Builder
Builds DirectWriteRolloverStrategy instances.
-
Field Summary
Fields Modifier and Type Field Description private int
compressionLevel
private java.lang.String
currentFileName
private java.util.List<Action>
customActions
private static int
DEFAULT_MAX_FILES
private int
maxFiles
Index for most recent log file.private int
nextIndex
private boolean
stopCustomActionsOnError
private PatternProcessor
tempCompressedFilePattern
private boolean
usePrevTime
-
Fields inherited from class org.apache.logging.log4j.core.appender.rolling.AbstractRolloverStrategy
LOGGER, PATTERN_COUNTER, strSubstitutor
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
DirectWriteRolloverStrategy(int maxFiles, int compressionLevel, StrSubstitutor strSubstitutor, Action[] customActions, boolean stopCustomActionsOnError)
Deprecated.Since 2.9 Added tempCompressedFilePatternString parameterprotected
DirectWriteRolloverStrategy(int maxFiles, int compressionLevel, StrSubstitutor strSubstitutor, Action[] customActions, boolean stopCustomActionsOnError, java.lang.String tempCompressedFilePatternString)
Constructs a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
clearCurrentFileName()
static DirectWriteRolloverStrategy
createStrategy(java.lang.String maxFiles, java.lang.String compressionLevelStr, Action[] customActions, boolean stopCustomActionsOnError, Configuration config)
Deprecated.Since 2.9 Usage of Builder API is preferableint
getCompressionLevel()
java.lang.String
getCurrentFileName(RollingFileManager manager)
java.util.List<Action>
getCustomActions()
int
getMaxFiles()
PatternProcessor
getTempCompressedFilePattern()
boolean
isStopCustomActionsOnError()
static DirectWriteRolloverStrategy.Builder
newBuilder()
private int
purge(RollingFileManager manager)
RolloverDescription
rollover(RollingFileManager manager)
Performs the rollover.java.lang.String
toString()
-
Methods inherited from class org.apache.logging.log4j.core.appender.rolling.AbstractRolloverStrategy
getEligibleFiles, getEligibleFiles, getEligibleFiles, getEligibleFiles, getEligibleFiles, getStrSubstitutor, merge, suffixLength
-
-
-
-
Field Detail
-
DEFAULT_MAX_FILES
private static final int DEFAULT_MAX_FILES
- See Also:
- Constant Field Values
-
maxFiles
private final int maxFiles
Index for most recent log file.
-
compressionLevel
private final int compressionLevel
-
customActions
private final java.util.List<Action> customActions
-
stopCustomActionsOnError
private final boolean stopCustomActionsOnError
-
currentFileName
private volatile java.lang.String currentFileName
-
nextIndex
private int nextIndex
-
tempCompressedFilePattern
private final PatternProcessor tempCompressedFilePattern
-
usePrevTime
private volatile boolean usePrevTime
-
-
Constructor Detail
-
DirectWriteRolloverStrategy
@Deprecated protected DirectWriteRolloverStrategy(int maxFiles, int compressionLevel, StrSubstitutor strSubstitutor, Action[] customActions, boolean stopCustomActionsOnError)
Deprecated.Since 2.9 Added tempCompressedFilePatternString parameterConstructs a new instance.- Parameters:
maxFiles
- The maximum number of files that match the date portion of the pattern to keep.customActions
- custom actions to perform asynchronously after rolloverstopCustomActionsOnError
- whether to stop executing asynchronous actions if an error occurs
-
DirectWriteRolloverStrategy
protected DirectWriteRolloverStrategy(int maxFiles, int compressionLevel, StrSubstitutor strSubstitutor, Action[] customActions, boolean stopCustomActionsOnError, java.lang.String tempCompressedFilePatternString)
Constructs a new instance.- Parameters:
maxFiles
- The maximum number of files that match the date portion of the pattern to keep.customActions
- custom actions to perform asynchronously after rolloverstopCustomActionsOnError
- whether to stop executing asynchronous actions if an error occurstempCompressedFilePatternString
- File pattern of the working file used during compression, if null no temporary file are used
-
-
Method Detail
-
newBuilder
@PluginBuilderFactory public static DirectWriteRolloverStrategy.Builder newBuilder()
-
createStrategy
@Deprecated @PluginFactory public static DirectWriteRolloverStrategy createStrategy(@PluginAttribute("maxFiles") java.lang.String maxFiles, @PluginAttribute("compressionLevel") java.lang.String compressionLevelStr, @PluginElement("Actions") Action[] customActions, @PluginAttribute(value="stopCustomActionsOnError",defaultBoolean=true) boolean stopCustomActionsOnError, @PluginConfiguration Configuration config)
Deprecated.Since 2.9 Usage of Builder API is preferableCreates the DirectWriteRolloverStrategy.- Parameters:
maxFiles
- The maximum number of files that match the date portion of the pattern to keep.compressionLevelStr
- The compression level, 0 (less) through 9 (more); applies only to ZIP files.customActions
- custom actions to perform asynchronously after rolloverstopCustomActionsOnError
- whether to stop executing asynchronous actions if an error occursconfig
- The Configuration.- Returns:
- A DirectWriteRolloverStrategy.
-
getCompressionLevel
public int getCompressionLevel()
-
getCustomActions
public java.util.List<Action> getCustomActions()
-
getMaxFiles
public int getMaxFiles()
-
isStopCustomActionsOnError
public boolean isStopCustomActionsOnError()
-
getTempCompressedFilePattern
public PatternProcessor getTempCompressedFilePattern()
-
purge
private int purge(RollingFileManager manager)
-
getCurrentFileName
public java.lang.String getCurrentFileName(RollingFileManager manager)
- Specified by:
getCurrentFileName
in interfaceDirectFileRolloverStrategy
-
clearCurrentFileName
public void clearCurrentFileName()
- Specified by:
clearCurrentFileName
in interfaceDirectFileRolloverStrategy
-
rollover
public RolloverDescription rollover(RollingFileManager manager) throws java.lang.SecurityException
Performs the rollover.- Specified by:
rollover
in interfaceRolloverStrategy
- Parameters:
manager
- The RollingFileManager name for current active log file.- Returns:
- A RolloverDescription.
- Throws:
java.lang.SecurityException
- if an error occurs.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-