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

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

Based on my other post I could come up with one solution:
# All the {{<IfFileName>}}, {{<IfFileSize>}} and accumulators are regarded as 
conditions.  But please don't use the {{If}} prefix, because they are boolean 
conditions instead of void expressions (like the java {{if}}).
# Additionally you provide two or three combining conditions:
## An {{<Or>}} element (you could call it {{<AnyOf>}} if there are class name 
clashes). It contains one or more conditions. All of them are evaluated (no 
shortcut operation).
## An {{<And>}} element (you could call it {{<AllOf>}} if there are class name 
clashes). It contains one or more conditions. All of them are evaluated (no 
shortcut operation).
## A {{<Not>}} element (I can't find usecases for it).
# You need one {{<ThenIf>}}, which is the shortcut operator.
# You require below the {{<Delete>}}, {{<ThenIf>}} and {{<Not>}} exactly one 
condition (which could be the combining condition). This avoids confusion how 
the conditions are combined.
# You allow below the {{<Delete>}} or {{<ThenIf>}} at most one {{<ThenIf>}}. 
Only if no {{<ThenIf>}} is provided, all files matching the condition are 
deleted. This ensures, that there is only one logical position for the implicit 
{{delete()}} per {{<Delete>}} element.

The result would be for my 3rd case:
{code:xml}
<Delete>
  <And>
    <FileName glob="debug-*.log" />
    <LastModified age="30d" />
  </And>
  <ThenIf>
    <Or>
      <AccumulatedFileSize exceeds="100 mb" />
      <AccumulatedFileCount exceeds="10" />
    </Or>
  </ThenIf>
</Delete>
{code}

Funnily, there is only one solution for the more complex example with combined 
accumulators. This is a good indication, that the definition is not redundant:
{code:xml}
<Delete baseDir="logs">
  <Or>
    <And>
      <LastModified age="90d"/>
      <FileSize exceeds="100M" />
    </And>
    <And>
      <FileName glob="**/*.log.gz" />
      <LastModified age="7dT1h" />
    </And>
    <And>
      <FileName pattern="\d+-\d{2}/app-[/]*-\d+\.log.gz" />
      <LastModified age="7d" />
    </And>
    <LastModified age="180d" />
  </Or>
</Delete>
<Delete baseDir="logs">
  <Or>
    <FileName pattern="\d+-\d{2}/app-[/]*-\d+\.log.gz" />
    <And>
      <FileName glob="**" />
      <LastModified age="30d" />
    </And>
  </Or>
  <ThenIf>
    <Or>
      <AccumulatedFileCount exceeds="100" />
      <AccumulatedFileSize exceeds="10gb" />
      <And>
        <AccumulatedFileCount count="90" />
        <AccumulatedFileSize exceeds="9gb" />
      </And>
    </Or>
  </ThenIf>
</Delete>
{code}

How do you like that?

> 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

Reply via email to