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

Robert Schaft edited comment on LOG4J2-435 at 12/2/15 2:19 PM:
---------------------------------------------------------------

What I proposed in my post with all the triggers, filters, and sets could be 
translated to:
{code:xml}
<Delete baseDir="logs">
  <If>
    <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>
    <Then>
      <DeleteIt/>
    </Then>
  </If>
</Delete>
<Delete baseDir="logs">
  <If>
    <Or>
      <FileName pattern="\d+-\d{2}/app-[/]*-\d+\.log.gz" />
      <And>
        <FileName glob="**" />
        <LastModified age="30d" />
      </And>
    </Or>
    <Then>
      <If>
        <Or>
          <AccumulatedFileCount exceeds="100" />
          <AccumulatedFileSize exceeds="10gb" />
          <And>
            <AccumulatedFileCount count="90" />
            <AccumulatedFileSize exceeds="9gb" />
          </And>
        </Or>
        <Then>
          <DeleteIt />
        </Then>
      </If>
    </Then>
  </If>
</Delete>
{code}
Hey, that works, too!

Ok, translating it to your vocabulary:
# Replace all {{<If><Or>}} with {{<IfAny>}}. First observation: it seems that 
{{<IfAll><Or>}} or {{<IfAny>}} is the same. You could drop {{<IfAny>}} and your 
vocabulary doesn't loose any expressiveness. I'll keep it nonetheless to come 
to a similar solution as you would be.
# Replace all {{<If><And>}} with {{<IfAll>}}. Nothing to do. There is no 
{{<If><And>}} in this example.
# Replace the {{<Then><IfAll>}} with {{<ThenAlsoCheck>}}. Problem: {{<Then>}} 
comes in this example with {{<IfAny>}}. Workaround: Replace {{<Then><IfAny>}} 
with {{<Then><IfAll><Or>}}, which could be replaced with 
{{<ThenAlsoCheck><Or>}}.
# Drop all {{<Then><DeleteIt/></Then>}}. No problems. It seems to be totally 
redundant and is always clear where it stands (in {{<If>}} s that have neither 
a {{<Then>}} nor a {{<Else>}} branch (not sure about the latter)).
# Drop the top level {{<IfAll>}}. To bad. There is none. Top level is 
{{<IfAny>}}. So I have to work around it by replacing top level {{<IfAny>}} 
with {{<IfAll><Or>}} and delete the {{<IfAll>}} part (effectively {{<IfAny>}} 
becomes {{<Or>}} at top level).

Result:
{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>
    <ThenAlsoCheck>
      <Or>
        <AccumulatedFileCount exceeds="100" />
        <AccumulatedFileSize exceeds="10gb" />
        <And>
          <AccumulatedFileCount count="90" />
          <AccumulatedFileSize exceeds="9gb" />
        </And>
      </Or>
    </ThenAlsoCheck>
  </Or>
</Delete>
{code}


was (Author: robert.schaft):
What I proposed in my post with all the triggers, filters, and sets could be 
translated to:
{code:xml}
<Delete baseDir="logs">
  <If>
    <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>
    <Then>
      <DeleteIt/>
    </Then>
  </If>
</Delete>
<Delete baseDir="logs">
  <If>
    <Or>
      <FileName pattern="\d+-\d{2}/app-[/]*-\d+\.log.gz" />
      <And>
        <FileName glob="**" />
        <LastModified age="30d" />
      </And>
    </Or>
    <Then>
      <If>
        <Or>
          <AccumulatedFileCount exceeds="100" />
          <AccumulatedFileSize exceeds="10gb" />
          <And>
            <AccumulatedFileCount count="90" />
            <AccumulatedFileSize exceeds="9gb" />
          </And>
        </Or>
        <Then>
          <DeleteIt />
        </Then>
      </If>
    </Then>
  </If>
</Delete>
{code}
Hey, that works, too!

Ok, translating it to your vocabulary:
# Replace all {{<If><Or>}} with {{<IfAny>}}. First observation: it seems that 
{{<IfAll><Or>}} or {{<IfAny>}} is the same. You could drop {{<IfAny>}} and your 
vocabulary doesn't loose any expressiveness. I'll keep it nonetheless to come 
to a similar solution as you would be.
# Replace all {{<If><And>}} with {{<IfAll>}}. Nothing to do. There is no 
{{<If><And>}} in this example.
# Replace the {{<Then><IfAll>}} with {{<ThenAlsoCheck>}}. Problem: {{<Then>}} 
comes in this example with {{<IfAny>}}. Workaround: Replace {{<Then><IfAny>}} 
with {{<Then><IfAll><Or>}}, which could be replaced with 
{{<ThenAlsoCheck><Or>}}.
# Drop all {{<Then><DeleteIt/></Then>}}. No problems. It seems to be totally 
redundant and is always clear where it stands (in {{<If>}}s that have neither a 
{{<Then>}} nor a {{<Else>}} branch (not sure about the latter)).
# Drop the top level {{<IfAll>}}. To bad. There is none. Top level is 
{{<IfAny>}}. So I have to work around it by replacing top level {{<IfAny>}} 
with {{<IfAll><Or>}} and delete the {{<IfAll>}} part (effectively {{<IfAny>}} 
becomes {{<Or>}} at top level).

Result:
{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>
    <ThenAlsoCheck>
      <Or>
        <AccumulatedFileCount exceeds="100" />
        <AccumulatedFileSize exceeds="10gb" />
        <And>
          <AccumulatedFileCount count="90" />
          <AccumulatedFileSize exceeds="9gb" />
        </And>
      </Or>
    </ThenAlsoCheck>
  </Or>
</Delete>
{code}

> 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