Rolling or RollingFileAppender is a type of log appender that rolls over log files.
For example, the appender logs to a file and when a certain condition is met, the logging
target changes to another file.
To change the appender, add the following element to the logback.xml file:
- TimeBasedRollingPolicy
- SizeBasedTriggeringPolicy
- SizeAndTimeBasedRollingPolicy
- FixedWindowRollingPolicy
To configure each policy, set these attributes:
- MaxFileSize - Determines the maximum size of a single log file before it gets
archived.
- MaxHistory - Determines the limit of archive files. Once this limit is met, the system
automatically deletes older archived files.
- TotalSizeCap - Determines the maximum size of log files including active and archived
logs. Once this limit is met, the system starts deleting older archived files
irrespective if the MaxHistory limit is met or not.
The following is an example of the logback.xml
file with the appender
attributes:
<appender name="destAccess" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${MX_TRACE_FILE_PATH}/EXC_AccessCheck.log</File>
<encoder>
<pattern>[%d{ISO8601}] :: %m%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${MX_TRACE_FILE_PATH}/EXC_AccessCheck-%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
<!-- each file should be at most 150MB, keep 7 days worth of history, but at most 1GB -->
<maxFileSize>150MB</maxFileSize>
<maxHistory>7</maxHistory>
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
</appender>
For more information, see the logback documentation at http://logback.qos.ch/manual/.