Class IfFileName
- java.lang.Object
-
- org.apache.logging.log4j.core.appender.rolling.action.IfFileName
-
- All Implemented Interfaces:
PathCondition
@Plugin(name="IfFileName", category="Core", printObject=true) public final class IfFileName extends java.lang.Object implements PathCondition
PathCondition that accepts files for deletion if their relative path matches either a glob pattern or a regular expression. If both a regular expression and a glob pattern are specified the glob pattern is used and the regular expression is ignored.The regular expression is a pattern as defined by the
Pattern
class. A glob is a simplified pattern expression described inFileSystem.getPathMatcher(String)
.
-
-
Field Summary
Fields Modifier and Type Field Description private static Logger
LOGGER
private PathCondition[]
nestedConditions
private java.nio.file.PathMatcher
pathMatcher
private java.lang.String
syntaxAndPattern
-
Fields inherited from interface org.apache.logging.log4j.core.appender.rolling.action.PathCondition
EMPTY_ARRAY
-
-
Constructor Summary
Constructors Modifier Constructor Description private
IfFileName(java.lang.String glob, java.lang.String regex, PathCondition... nestedConditions)
Constructs a FileNameFilter filter.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
accept(java.nio.file.Path basePath, java.nio.file.Path relativePath, java.nio.file.attribute.BasicFileAttributes attrs)
Returnstrue
if the specified candidate path should be deleted,false
otherwise.void
beforeFileTreeWalk()
Invoked before a new file tree walk is started.static IfFileName
createNameCondition(java.lang.String glob, java.lang.String regex, PathCondition... nestedConditions)
Creates a IfFileName condition that returns true if either the specified glob pattern or the regular expression matches the relative path.(package private) static java.lang.String
createSyntaxAndPatternString(java.lang.String glob, java.lang.String regex)
java.util.List<PathCondition>
getNestedConditions()
java.lang.String
getSyntaxAndPattern()
Returns the baseDir-relative path pattern of the files to delete.java.lang.String
toString()
-
-
-
Field Detail
-
LOGGER
private static final Logger LOGGER
-
pathMatcher
private final java.nio.file.PathMatcher pathMatcher
-
syntaxAndPattern
private final java.lang.String syntaxAndPattern
-
nestedConditions
private final PathCondition[] nestedConditions
-
-
Constructor Detail
-
IfFileName
private IfFileName(java.lang.String glob, java.lang.String regex, PathCondition... nestedConditions)
Constructs a FileNameFilter filter. If both a regular expression and a glob pattern are specified the glob pattern is used and the regular expression is ignored.- Parameters:
glob
- the baseDir-relative path pattern of the files to delete (may contain '*' and '?' wildcarts)regex
- the regular expression that matches the baseDir-relative path of the file(s) to deletenestedConditions
- nested conditions to evaluate if this condition accepts a path
-
-
Method Detail
-
createSyntaxAndPatternString
static java.lang.String createSyntaxAndPatternString(java.lang.String glob, java.lang.String regex)
-
getSyntaxAndPattern
public java.lang.String getSyntaxAndPattern()
Returns the baseDir-relative path pattern of the files to delete. The returned string takes the formsyntax:pattern
where syntax is one of "glob" or "regex" and the pattern is either a regular expression or a simplified pattern expression described under "glob" inFileSystem.getPathMatcher(String)
.- Returns:
- relative path of the file(s) to delete (may contain regular expression or wildcarts)
-
getNestedConditions
public java.util.List<PathCondition> getNestedConditions()
-
accept
public boolean accept(java.nio.file.Path basePath, java.nio.file.Path relativePath, java.nio.file.attribute.BasicFileAttributes attrs)
Description copied from interface:PathCondition
Returnstrue
if the specified candidate path should be deleted,false
otherwise.- Specified by:
accept
in interfacePathCondition
- Parameters:
basePath
- the directory from where to start scanning for deletion candidate filesrelativePath
- the candidate for deletion. This path is relative to the baseDir.attrs
- attributes of the candidate path- Returns:
- whether the candidate path should be deleted
-
beforeFileTreeWalk
public void beforeFileTreeWalk()
Description copied from interface:PathCondition
Invoked before a new file tree walk is started. Stateful PathConditions can reset their state when this method is called.- Specified by:
beforeFileTreeWalk
in interfacePathCondition
-
createNameCondition
@PluginFactory public static IfFileName createNameCondition(@PluginAttribute("glob") java.lang.String glob, @PluginAttribute("regex") java.lang.String regex, @PluginElement("PathConditions") PathCondition... nestedConditions)
Creates a IfFileName condition that returns true if either the specified glob pattern or the regular expression matches the relative path. If both a regular expression and a glob pattern are specified the glob pattern is used and the regular expression is ignored.- Parameters:
glob
- the baseDir-relative path pattern of the files to delete (may contain '*' and '?' wildcarts)regex
- the regular expression that matches the baseDir-relative path of the file(s) to deletenestedConditions
- nested conditions to evaluate if this condition accepts a path- Returns:
- A IfFileName condition.
- See Also:
FileSystem.getPathMatcher(String)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-