You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Remko Popma (JIRA)" <ji...@apache.org> on 2015/09/03 05:21:45 UTC

[jira] [Comment Edited] (LOG4J2-435) Support limiting number of log files based on date pattern

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

Remko Popma edited comment on LOG4J2-435 at 9/3/15 3:21 AM:
------------------------------------------------------------

I suspect that people may have different requirements on which files can be deleted.
Rather than a maxAge attribute, perhaps we can introduce a {{DeletePolicy}}, with a set of conditions that select files to delete. An example follows below:

{code}
<RollingRandomAccessFile name="RollingRandomAccessFile" fileName="logs/app.log"
             filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">
  <PatternLayout>
    <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
  </PatternLayout>
  <Policies>
    <TimeBasedTriggeringPolicy />
    <SizeBasedTriggeringPolicy size="250 MB"/>
  </Policies>
  <DeletePolicy baseDirectory="logs"><!-- start looking in the logs directory -->
    <And> <!-- both of the nested conditions must be true -->
      <FileAgeCondition age="15d" /> <!-- files age is 15 days or older -->
      <NameMatchCondition pattern=".*/app.*\\.log\\.gz" /> <!-- file name matches regular expression -->
    </And>
  </DeletePolicy>
</RollingRandomAccessFile>
{code}

The advantage of this approach is that it allows users to write their own condition plugins to select which files to delete.


was (Author: remkop@yahoo.com):
I suspect that people may have different requirements on which files can be deleted.
Rather than a maxAge attribute, perhaps we can introduce a {{DeletePolicy}}, with a set of conditions that select files to delete. An example follows below:

{code}
<RollingRandomAccessFile name="RollingRandomAccessFile" fileName="logs/app.log"
             filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">
  <PatternLayout>
    <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
  </PatternLayout>
  <Policies>
    <TimeBasedTriggeringPolicy />
    <SizeBasedTriggeringPolicy size="250 MB"/>
  </Policies>
  <DeletePolicy baseDirectory="logs"><!-- start looking in the logs directory -->
    <And> <!-- both of the nested conditions must be true -->
      <FileAgeCondition age="15d" /> <!-- files age is 15 days or older -->
      <NameMatchCondition pattern=".*/app.*\\.log\\.gz" /> <!-- file name matches regular expression -->
    </And>
  </DeletePolicy>
</RollingRandomAccessFile>
{code}

> 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: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org