LoggerAppenderDailyFile

LoggerAppenderDailyFile writes logging events to a file. The file is rolled over once a day. In other words, for each day a new file is created.

The path specified in the file parameter string should contain the string %s which will be substituted with the current date when logging. The datePattern parameter determines how the date will be formatted.

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.
datePattern string No Ymd Format for the date in the file path, follows formatting rules used by the PHP date() function.

Examples

This example shows how to configure LoggerAppenderDailyFile.

The date pattern used is Y-m-d which will result in filenames similar to file-2011-10-01.log.

  • XML
  • PHP
<configuration xmlns="http://logging.apache.org/log4php/">
    <appender name="default" class="LoggerAppenderDailyFile">
        <layout class="LoggerLayoutTTCC" />
        <param name="file" value="file-%s.log" />
        <param name="datePattern" value="Y-m-d" />
    </appender>
    <root>
        <appender_ref ref="default" />
    </root>
</configuration>
array(
    'appenders' => array(
        'default' => array(
            'class' => 'LoggerAppenderDailyFile',
            'layout' => array(
                'class' => 'LoggerLayoutTTCC',
            ),
            'params' => array(
                'datePattern' => 'Y-m-d',
                'file' => 'file-%s.log',
            ),
        ),
    ),
    'rootLogger' => array(
        'appenders' => array('default'),
    ),
);