[
https://issues.apache.org/jira/browse/LOG4J2-435?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Robert Schaft updated LOG4J2-435:
---------------------------------
Attachment: SizeParser.java
LimitingRolloverStrategy.java
I tried an implementation.
My central problems were:
* There is no way to access the filePattern attribute from within the
RolloverStrategy. So the RolloverStrategy has to be modified.
* Even if the filePattern could be accessed, it is complicated and error prone
to separate the static path from the dynamic path:
{{filePattern="logs/errors-%d\{yyyy\}/errors-%d\{yyyyMMdd\}-%i.log.gz"}} has a
static path {{"./logs"}} and a dynamic part
{{"errors-\d+/errors-\d+-(?<index>\d+).log.gz"}}. This is necessary to limit
the search scope of the Limiter to a reasonable part of the filesystem. The
Limiter would monitor all files below the static path that match the dynamic
part and delete files until the maxFiles, maxSize and maxAge restrictions are
obeyed.
** Another tricky part is: The filePattern could be separated by slashes on
unix systems or by slashes or backslashes on windows systems. And are there
other separators around? What should be used as directory separator?
So my so conclusion would be: Extend the RollingFileExtender by a
ArchiveLimitingPolicy similar to the policies. We can than have an
AgeBasedLimiter that looks just for the lastModified date, a
FileCounterLimiter, a TotalFileSizeLimiter...
* The ArchiveLimitingPolicy provides the limiters with a list of matching files
(and their {{BasicFileAttributes}} and index) would reduce redundant initial
file system scan code.
* The constructor of ArchiveLimitingPolicy needs access to the filePatterhn
* It is important for the limiters to be created once and notified for every
change - even if another limiter has deleted the files. This way they could
keep an internal (ordered) list of matching files.
I attached the LimitingRolloverStrategy I wrote.
> Support limiting number of log files based on date pattern
> ----------------------------------------------------------
>
> Key: LOG4J2-435
> URL: https://issues.apache.org/jira/browse/LOG4J2-435
> Project: Log4j 2
> Issue Type: Improvement
> Reporter: Arkin Yetis
> Assignee: Ralph Goers
> Labels: Rollover
> Attachments: LimitingRolloverStrategy.java, SizeParser.java
>
>
> 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.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]