Class ScriptCondition
java.lang.Object
org.apache.logging.log4j.core.appender.rolling.action.ScriptCondition
@Plugin(name="ScriptCondition",
category="Core",
printObject=true)
public class ScriptCondition
extends Object
A condition of the
DeleteAction where a user-provided script selects the files to delete from a provided
list. The specified script may be a Script, a ScriptFile or a ScriptRef.-
Constructor Summary
ConstructorsConstructorDescriptionScriptCondition(AbstractScript script, Configuration configuration) Constructs a new ScriptCondition. -
Method Summary
Modifier and TypeMethodDescriptionstatic ScriptConditioncreateCondition(AbstractScript script, Configuration configuration) Creates the ScriptCondition.selectFilesToDelete(Path basePath, List<PathWithAttributes> candidates) Executes the script
-
Constructor Details
-
ScriptCondition
Constructs a new ScriptCondition.- Parameters:
script- the script that can select files to deleteconfiguration- configuration containing the StrSubstitutor passed to the script
-
-
Method Details
-
selectFilesToDelete
public List<PathWithAttributes> selectFilesToDelete(Path basePath, List<PathWithAttributes> candidates) Executes the script- Parameters:
basePath- base directory for files to deletecandidates- a list of paths, that can be deleted by the script- Returns:
- a list of paths selected to delete by the script execution
-
createCondition
@PluginFactory public static ScriptCondition createCondition(@PluginElement("Script") AbstractScript script, @PluginConfiguration Configuration configuration) Creates the ScriptCondition.- Parameters:
script- The script to run. This may be aScript, aScriptFileor aScriptRef. The script must return aList<PathWithAttributes>. When the script is executed, it is provided the following bindings:- basePath - the directory from where the
Deleteaction started scanning for files to delete. Can be used to relativize the paths in the pathList. - pathList - a
java.util.ListcontainingPathWithAttributesobjects. (The script is free to modify and return this list.) - substitutor - a
StrSubstitutorthat can be used to look up variables embedded in the base dir or other properties - statusLogger - the
StatusLoggerthat can be used to log events during script execution - any properties declared in the configuration
- basePath - the directory from where the
configuration- the configuration- Returns:
- A ScriptCondition.
-