Reputation: 21
I want to configure log4j2.xml will below configuration.If My log file size increase than 5 MB ,it should create new Files.and on next day All file will be compressed and stores into zip with date format. e.g for 01-06-2015 applog.log 2 MB, 01-06-2015 applog.log.1 3 MB, 01-06-2015 applog.log.2 3 MB, 01-06-2015 applog.log.3 3 MB On 01-0702015 ,It all should be compressed and stored into folder applog-%d{dd-MM}-%i.zip My current Configuration is below:
<appenders>
<RollingFile name="applog_Appender" fileName="D:/logs/applog.log"
filePattern="D:/logs/$${date:yyyy-MM}/app-%d{dd-MM-yyyy}-%i.zip">
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="3 MB"/>
</Policies>
<DefaultRolloverStrategy max="15" />
</RollingFile>
</appenders>
With this configuration,It will create only zip with applog.log. I want applog.log ....applog.log.n of one day to be compressed and create zip
Upvotes: 2
Views: 3064
Reputation: 36754
Log4j2 cannot zip multiple files on rollover. The current rollover logic simply renames the current log file and optionally zips it. That's all it does. You may need to create a custom script to combine multiple old log files into a single archive.
Update: Log4j 2.5 introduced the ability to have custom actions execute on rollover. Currently DeleteAction is the only built-in action, but you can create your own custom action to zip multiple files.
Upvotes: 4