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.
See Also:
  • Constructor Details

    • ScriptCondition

      public ScriptCondition(AbstractScript script, Configuration configuration)
      Constructs a new ScriptCondition.
      Parameters:
      script - the script that can select files to delete
      configuration - 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 delete
      candidates - 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 a Script, a ScriptFile or a ScriptRef. The script must return a List<PathWithAttributes>. When the script is executed, it is provided the following bindings:
      • basePath - the directory from where the Delete action started scanning for files to delete. Can be used to relativize the paths in the pathList.
      • pathList - a java.util.List containing PathWithAttributes objects. (The script is free to modify and return this list.)
      • substitutor - a StrSubstitutor that can be used to look up variables embedded in the base dir or other properties
      • statusLogger - the StatusLogger that can be used to log events during script execution
      • any properties declared in the configuration
      configuration - the configuration
      Returns:
      A ScriptCondition.