[ 
https://issues.apache.org/jira/browse/LOG4J2-435?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14532935#comment-14532935
 ] 

Robert Schaft commented on LOG4J2-435:
--------------------------------------

>From my point of view a date pattern {{%d}} and the DefaultRolloverStrategy 
>{{max}} attribute are incompatible, because the DefaultRolloverStrategy can 
>restart its {{%i}} counter each time the {{%d}} pattern changes and loses all 
>files with a different %d.
Unfortunately, TimeBasedTriggeringPolicy requires a date pattern.

h3. Solution A
DefaultRolloverStrategy gets a new parameter {{totalMax}}. For this parameter, 
the file search for existing old log files replaces all {{%d}} and similar time 
based placeholders with a {{*}}-like glob.

h3. Solution B
A new {{LimitingRolloverStrategy}} similar DefaultRolloverStrategy but with a 
different handling:
It has a parameter {{scopeFilePattern}}. This pattern is basically the filter 
which files should be included in the calculation plus the {{%i}} to know where 
the counter sits: {{"logs/\d+/foo-%i.log.gz"}} would result in a file search 
pattern {{"logs/\\d+/foo-\\d+.log.gz"}}.
All those files are kept in account. And the maximum value that was found for 
the %i placeholder will be increased to get the new value for {{%i}}.
There must be no max-Value for {{%i}} because it would somehow lead to the 
situation where the code must rename files in old (lower %d value) folders. 
This is not a good idea in regards of backup strategies etc.

Instead I suggest the following attributes:
- The {{maxFiles}} attribute would say, how many files should match. If more 
files match, the files with the smallest %i would be deleted. If there are more 
than one with same %i? Delete all! That way a configuration error is quickly 
revealed.
- A {{maxSize}} like {{100 MB}} could be implemented in the same manner: Delete 
low %i values until the value is obeyed. Another advantage: If the logfiles 
could be well compressed, more files are kept.
- Even a {{maxAge}} with ISO8601 Period like {{P3w}} is thinkable. It would 
look at the lastModified timestamp (looking at {{%d}} is would be too error 
prone).
- The {{min}} attribute could be used if no matching file was found or to have 
a minimum {{%i}} like 1000 (which forces to have at least 4 digit %i).

Comment are welcome.

> 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
>
> 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]

Reply via email to