Class DeleteAction
java.lang.Object
org.apache.logging.log4j.core.appender.rolling.action.AbstractAction
org.apache.logging.log4j.core.appender.rolling.action.AbstractPathAction
org.apache.logging.log4j.core.appender.rolling.action.DeleteAction
@Plugin(name="Delete",
category="Core",
printObject=true)
public class DeleteAction
extends AbstractPathAction
Rollover or scheduled action for deleting old log files that are accepted by the specified PathFilters.
-
Field Summary
Fields inherited from class org.apache.logging.log4j.core.appender.rolling.action.AbstractAction
LOGGER -
Method Summary
Modifier and TypeMethodDescriptionstatic DeleteActioncreateDeleteAction(String basePath, boolean followLinks, int maxDepth, boolean testMode, PathSorter sorterParameter, PathCondition[] pathConditions, ScriptCondition scriptCondition, Configuration config) Create a DeleteAction.protected FileVisitor<Path>createFileVisitor(Path visitorBaseDir, List<PathCondition> conditions) Creates a newFileVisitor<Path>to pass to theFiles.walkFileTree(Path, Set, int, FileVisitor)method when theAbstractPathAction.execute()method is invoked.protected voidDeletes the specified file.booleanexecute()Performs action.booleanexecute(FileVisitor<Path> visitor) booleanReturnstrueif files are not deleted even when all conditions accept a path,falseotherwise.Methods inherited from class org.apache.logging.log4j.core.appender.rolling.action.AbstractPathAction
getBasePath, getBasePathString, getMaxDepth, getOptions, getPathConditions, getStrSubstitutor, isFollowSymbolicLinks, toStringMethods inherited from class org.apache.logging.log4j.core.appender.rolling.action.AbstractAction
close, isComplete, isInterrupted, reportException, run
-
Method Details
-
execute
Description copied from class:AbstractActionPerforms action.- Specified by:
executein interfaceAction- Overrides:
executein classAbstractPathAction- Returns:
- true if successful.
- Throws:
IOException- if IO error.
-
delete
Deletes the specified file.- Parameters:
path- the file to delete- Throws:
IOException- if a problem occurred deleting the file
-
execute
- Overrides:
executein classAbstractPathAction- Throws:
IOException
-
isTestMode
public boolean isTestMode()Returnstrueif files are not deleted even when all conditions accept a path,falseotherwise.- Returns:
trueif files are not deleted even when all conditions accept a path,falseotherwise
-
createFileVisitor
Description copied from class:AbstractPathActionCreates a newFileVisitor<Path>to pass to theFiles.walkFileTree(Path, Set, int, FileVisitor)method when theAbstractPathAction.execute()method is invoked.The visitor is responsible for processing the files it encounters that are accepted by all filters.
- Specified by:
createFileVisitorin classAbstractPathAction- Parameters:
visitorBaseDir- base dir from where to start scanning for files to processconditions- filters that determine if a file should be processed- Returns:
- a new
FileVisitor<Path>
-
createDeleteAction
@PluginFactory public static DeleteAction createDeleteAction(@PluginAttribute("basePath") String basePath, @PluginAttribute("followLinks") boolean followLinks, @PluginAttribute(value="maxDepth",defaultInt=1) int maxDepth, @PluginAttribute("testMode") boolean testMode, @PluginElement("PathSorter") PathSorter sorterParameter, @PluginElement("PathConditions") PathCondition[] pathConditions, @PluginElement("ScriptCondition") ScriptCondition scriptCondition, @PluginConfiguration Configuration config) Create a DeleteAction.- Parameters:
basePath- base path from where to start scanning for files to delete.followLinks- whether to follow symbolic links. Default is false.maxDepth- The maxDepth parameter is the maximum number of levels of directories to visit. A value of 0 means that only the starting file is visited, unless denied by the security manager. A value of MAX_VALUE may be used to indicate that all levels should be visited.testMode- if true, files are not deleted but instead a message is printed to the status logger at INFO level. Users can use this to do a dry run to test if their configuration works as expected. Default is false.sorterParameter- a plugin implementing thePathSorterinterfacepathConditions- an array of path conditions (if more than one, they all need to accept a path before it is deleted).config- The Configuration.- Returns:
- A DeleteAction.
-