[
https://issues.apache.org/jira/browse/LOG4J2-656?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17454280#comment-17454280
]
Remko Popma commented on LOG4J2-656:
------------------------------------
[~aadit] this may be possible by using a ScriptCondition for the delete action.
(search for "ScriptCondition Parameters" in the [appenders manual
page|[https://logging.apache.org/log4j/2.x/manual/appenders.html#CustomDeleteOnRollover].]
The manual says "The Script element that specifies the logic to be executed.
The script is passed a list of paths found under the base path and must return
the paths to delete as a
java.util.List<[PathWithAttributes|https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/appender/rolling/action/PathWithAttributes.html]>."
That looks promising. :) Can you play with that to see if you can return a
directory to delete with this mechanism?
> How to delete rolled over folder older than six months.
> -------------------------------------------------------
>
> Key: LOG4J2-656
> URL: https://issues.apache.org/jira/browse/LOG4J2-656
> Project: Log4j 2
> Issue Type: Question
> Components: Appenders
> Affects Versions: 2.0-rc1
> Environment: Java 7
> Reporter: sivan
> Priority: Major
> Labels: Rollover
>
> My application is using Rolling file appender. So the log files are daily
> rolled over to the folder having name yyyy-MM. ie 2014-03, 2014-04, 2014-05
> etc. Now the requirement is to delete 6 months older folder from the path.
> Is there any configuration to achieve this?
> The current configuration is as below.
> <?xml version="1.0" encoding="UTF-8"?>
> <configuration>
> <properties>
> <property name="logPattern">%c|%K{sessionId}|%t|%d{MM/dd/yyyy
> HH:mm:ss.SSS}|%p|%C|%M|%L|%K{msg}%n</property>
> <property
> name="filePattern">${sys:logfilepath}//$${date:yyyy-MM}//${sys:oft.appserver}-out-%d{yyyy-MM-dd}.log</property>
> <property
> name="fileName">${sys:logfilepath}//${sys:oft.appserver}-out.log</property>
> </properties>
> <appenders>
> <Console name="Console" target="SYSTEM_OUT">
> <PatternLayout pattern="logPattern"/>
> </Console>
> <RollingFile name="RollingFile" fileName="${fileName}"
> filePattern="${filePattern}">
> <PatternLayout>
> <pattern>${logPattern}</pattern>
> </PatternLayout>
> <Policies>
> <TimeBasedTriggeringPolicy />
> </Policies>
> </RollingFile>
> </appenders>
> <loggers>
> <AsyncLogger name="logtype" level="info" includeLocation="true"
> additivity="false">
> <AppenderRef ref="RollingFile"/>
> </AsyncLogger>
> <root level="info">
> <AppenderRef ref="Console"/>
> </root>
> </loggers>
> </configuration>
--
This message was sent by Atlassian Jira
(v8.20.1#820001)