LoggerAppenderRollingFile writes logging events to a specified file. The file is rolled over after a specified size has been reached.

For example, if logging to a file named file.log, when the file size reaches the specified size limit, the contents are archived in a file named file.log.1 and file.log is truncated. When the size limit is reached the second time, file.log.1 is renamed to file.log.2; contents from file.log are archived to file.log.1 and file.log is truncated

This continues until the maximum backup index is reached, after which the oldest log file is deleted on each rollover.


This appender requires a layout. If no layout is specified in configuration, LoggerLayoutSimple will be used by default.


The following parameters are available:

Parameter Type Required Default Description
file string Yes - Path to the target file. Should contain a %s which gets substituted by the date.
append boolean No true If set to true, the appender will append to the file, otherwise the file contents will be overwritten.
maxFileSize string No 10M Maximum allowed file size (in bytes) before rolling over. Suffixes "KB", "MB" and "GB" are allowed. 10KB = 10240 bytes, etc.
maxBackupIndex integer No 1 Maximum number of backup files to keep.
compress boolean No false If set to true, the rollover files are compressed and saved with the .gz extension.


This example shows how to configure LoggerAppenderRollingFile to rollover after reaching the size of 1MB and for keeping the last 5 backup files.

  • XML
  • PHP
<configuration xmlns="http://logging.apache.org/log4php/">
    <appender name="default" class="LoggerAppenderRollingFile">
        <layout class="LoggerLayoutSimple" />
        <param name="file" value="file.log" />
        <param name="maxFileSize" value="1MB" />
        <param name="maxBackupIndex" value="5" />
        <appender_ref ref="default" />
    'appenders' => array(
        'default' => array(
            'class' => 'LoggerAppenderRollingFile',
            'layout' => array(
                'class' => 'LoggerLayoutSimple',
            'params' => array(
                'file' => 'file.log',
                'maxFileSize' => '1MB',
                'maxBackupIndex' => 5,
    'rootLogger' => array(
        'appenders' => array('default'),