LoggerAppenderDailyFile writes logging events to a file which is rolled over depending on the date/time of the logging event. By default, the file is rolled over daily, hence the appender name. However, the appender can just as easily be configured to roll over once a month, or even every minute if desired.
Unlike LoggerAppenderFile, the target file is not static, and can change during script execution as the time passes. Destination file is determined by two parameters: file and datePattern.
The path specified in the file parameter should contain the string %s. Each time an event is logged, this string will be substituted with the event's date/time formatted according to datePattern and the event will be logged to the resulting file path.
The date/time is formatted according to format string specified in the datePattern parameter. The format uses the same rules as the PHP date() function. Any format string supported by date() function may be used as a date pattern.
This appender requires a layout. If no layout is specified in configuration, LoggerLayoutSimple will be used by default.
The following parameters are available:
Consider the following configuration:
<configuration xmlns="http://logging.apache.org/log4php/"> <appender name="default" class="LoggerAppenderDailyFile"> <layout class="LoggerLayoutSimple" /> <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' => 'LoggerLayoutSimple', ), 'params' => array( 'datePattern' => 'Y-m-d', 'file' => 'file-%s.log', ), ), ), 'rootLogger' => array( 'appenders' => array('default'), ), );
In this example, the date pattern is set to Y-m-d (year, month, day) and the target file to daily.%s.log.
Each time this appender receives a logging event, it will:
If you continue logging using the given configuration, the appender will continue to log to daily.2012-07-10.log, until the date changes. At that point it will start logging to daily.2012-07-11.log.
Similarly, date pattern Y-m will result in filenames like file-2012-07.log, which will result in monthly rollover.
Hours, minutes and seconds can also be used. Pattern Y-m-d.H.i.s will result in filenames similar to file-2012-07-03.10.37.15.log. In this case, a new file will be created each second.