[ https://issues.apache.org/jira/browse/LOG4J2-435?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15005216#comment-15005216 ]
Remko Popma commented on LOG4J2-435: ------------------------------------ Update: I am finding that Java 7's [Files.walkFileTree|http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#walkFileTree(java.nio.file.Path,%20java.util.Set,%20int,%20java.nio.file.FileVisitor)] API makes this relatively easy to implement. Sample configuration snippet: {code} <Delete baseDir="${sys:user.home}/myapp/logs" maxDepth="2" followLinks="false"> <And> <File path="*/myApp*.log.gz" /> <LastModified duration="7d" /> </And> </Delete> {code} * {{maxDepth}} determines how deep to recurse from the base directory. The default is 1: only scan files in the base directory itself. * {{followLinks}} deals with symbolic links. Default is false: on a match, the link is deleted, not the file it points to, and directory links are not recursed into. * _duration_: Supports the ISO8601 format, without Year or Month sections (like Java 8 [java.time.Duration|https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html#parse-java.lang.CharSequence-]). Unlike in Java 8's Duration, negative periods and fractions are not supported. In addition to the ISO8601 format, I also want to support a simplified format that allows omitting the prefix 'P' and infix 'T', accepting values like {{"7d"}} or {{"24H"}}. * _Regular expressions_ are powerful but not easy to read or write. I will support both regex matching and simple '*' and '?' wildcarts. Examples: {code} <!-- Regular expression: --> <File regex=".*/myApp.*\\.log\\.gz" /> <!-- Simple path with wildcarts: --> <File path="*/myApp*.log.gz" /> {code} Now working on integrating this with RollingFileAppender, and add tests and documentation. I will commit this soon. Feedback welcome. > Feature request: auto-delete older log files > --------------------------------------------- > > Key: LOG4J2-435 > URL: https://issues.apache.org/jira/browse/LOG4J2-435 > Project: Log4j 2 > Issue Type: Improvement > Reporter: Arkin Yetis > Assignee: Remko Popma > Labels: Rollover > Fix For: 2.5 > > Attachments: LimitingRolloverStrategy.java, SizeParser.java > > > Original description: > {quote} > DefaultRolloverStrategy max attribute only applies if you have a %i in the > file pattern. This request is to enhance DefaultRolloverStrategy or another > appropriate component to allow a max number of files limit to apply across > days/months/years when a filePattern includes a date pattern. > {quote} > ---- > One of the most requested features is to add the ability to Log4j to "clean > up" older log files. This usually means deleting these files, although it > could also mean moving them to a different location, or some combination of > these. > Users have different requirements for selecting the files to clean up. A > common request is the ability to keep the last X number of log files. This > works well if rollover is only date based but may give undesired results with > size based rollover. > Another factor to consider is that the directory containing the log files may > contain the log files for multiple appenders, or even files unrelated to > logging. -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-dev-h...@logging.apache.org