LoggerAppenderRollingFile

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.

Layout

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

Parameters

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.

Examples

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>
    <root>
        <appender_ref ref="default" />
    </root>
</configuration>
array(
    'appenders' => array(
        'default' => array(
            'class' => 'LoggerAppenderRollingFile',
            'layout' => array(
                'class' => 'LoggerLayoutSimple',
            ),
            'params' => array(
                'file' => 'file.log',
                'maxFileSize' => '1MB',
                'maxBackupIndex' => 5,
            ),
        ),
    ),
    'rootLogger' => array(
        'appenders' => array('default'),
    ),
);