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 java.lang.Object
A condition of theDeleteActionwhere a user-provided script selects the files to delete from a provided list. The specified script may be aScript, aScriptFileor aScriptRef.
-
-
Field Summary
Fields Modifier and Type Field Description private Configurationconfigurationprivate static LoggerLOGGERprivate AbstractScriptscript
-
Constructor Summary
Constructors Constructor Description ScriptCondition(AbstractScript script, Configuration configuration)Constructs a new ScriptCondition.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ScriptConditioncreateCondition(AbstractScript script, Configuration configuration)Creates the ScriptCondition.java.util.List<PathWithAttributes>selectFilesToDelete(java.nio.file.Path basePath, java.util.List<PathWithAttributes> candidates)Executes the script
-
-
-
Field Detail
-
LOGGER
private static Logger LOGGER
-
script
private final AbstractScript script
-
configuration
private final Configuration configuration
-
-
Constructor Detail
-
ScriptCondition
public ScriptCondition(AbstractScript script, Configuration configuration)
Constructs a new ScriptCondition.- Parameters:
script- the script that can select files to deleteconfiguration- configuration containing the StrSubstitutor passed to the script
-
-
Method Detail
-
selectFilesToDelete
public java.util.List<PathWithAttributes> selectFilesToDelete(java.nio.file.Path basePath, java.util.List<PathWithAttributes> candidates)
Executes the script- Parameters:
baseDir-candidates-- Returns:
-
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.ListcontainingPathWithAttributeobjects. (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.
-
-