Plop
A simple logging library for PHP
Plop\Handler\TimedRotatingFile Class Reference

An handler that writes logs to a file but also handles that file's rotation, based on time. More...

+ Inheritance diagram for Plop\Handler\TimedRotatingFile:

Public Member Functions

 __construct ($filename, $when= 'h', $interval=1, $backupCount=0, $delay=false, $utc=false)
 
- Public Member Functions inherited from Plop\Handler\File
 __construct ($filename, $mode= 'at', $delay=false)
 
 __destruct ()
 Free the resources used by this handler.
 
- Public Member Functions inherited from Plop\Handler\Stream
 __construct ($stream=null)
 
- Public Member Functions inherited from Plop\HandlerAbstract
 __construct (\Plop\FormatterInterface $formatter=null,\Plop\FiltersCollectionAbstract $filters=null)
 
 getFilters ()
 
 getFormatter ()
 
 handle (\Plop\RecordInterface $record)
 
 handleError (\Plop\RecordInterface $record,\Exception $exception)
 
 setFilters (\Plop\FiltersCollectionAbstract $filters)
 
 setFormatter (\Plop\FormatterInterface $formatter)
 

Protected Member Functions

 computeRollover ($currentTime)
 
 doRollover ()
 
 getFilesToDelete ()
 
 getTime ()
 
 shouldRollover (\Plop\RecordInterface $record)
 
- Protected Member Functions inherited from Plop\Handler\RotatingAbstract
 doRollover ()
 
 emit (\Plop\RecordInterface $record)
 
 shouldRollover (\Plop\RecordInterface $record)
 
- Protected Member Functions inherited from Plop\Handler\File
 close ()
 
 emit (\Plop\RecordInterface $record)
 
 open ()
 
- Protected Member Functions inherited from Plop\Handler\Stream
 emit (\Plop\RecordInterface $record)
 
 flush ()
 
- Protected Member Functions inherited from Plop\HandlerAbstract
 emit (\Plop\RecordInterface $record)
 
 format (\Plop\RecordInterface $record)
 
 getStderr ()
 

Protected Attributes

 $backupCount
 Number of backup log files to keep.
 
 $dayOfWeek
 Day of week (0=Monday...6=Sunday) when the log rotation happens.
 
 $extMatch
 A PCRE pattern that matches rotated files.
 
 $interval
 Interval between file rotations.
 
 $rolloverAt
 UNIX timestamp of the next log rotation.
 
 $suffix
 The date format that will be used as a suffix for the log files.
 
 $utc
 Whether the files are named based on UTC time or local time.
 
 $when
 Log rotation specification (eg. 'W' or 'MIDNIGHT').
 
- Protected Attributes inherited from Plop\Handler\File
 $baseFilename
 Path to the log file this handler writes to.
 
 $mode
 Opening mode for the log file.
 
- Protected Attributes inherited from Plop\Handler\Stream
 $stream
 The stream where log messages will be write to.
 
- Protected Attributes inherited from Plop\HandlerAbstract
 $filters
 An object handling a collection of filters.
 
 $formatter
 Formatter object to use for this handler.
 

Static Protected Attributes

static $dayNames
 The names of days in English, starting with Monday. More...
 
- Static Protected Attributes inherited from Plop\Handler\Stream
static $stderr = null
 A stream referencing STDERR.
 

Detailed Description

An handler that writes logs to a file but also handles that file's rotation, based on time.

Definition at line 29 of file TimedRotatingFile.php.

Constructor & Destructor Documentation

Plop\Handler\TimedRotatingFile::__construct (   $filename,
  $when = 'h',
  $interval = 1,
  $backupCount = 0,
  $delay = false,
  $utc = false 
)

Construct a new instance of this handler.

Parameters
string$filenameName of the log file to write to.
string$when(optional) A log rotation specification, which acts as a multiplier for the $interval parameter. The default value is "h". Valid (case-insensitive) values include
  • "s" – rotate the logs every $interval seconds.
  • "m" – rotate the logs every $interval minutes.
  • "h" – rotate the logs every $interval hours.
  • "d" – rotate the logs every $interval days.
  • "w0" through "w6" – rotate the logs every $interval weeks. The number after the "w" character indicates on what day of the week the log rotation will happen (0 means Monday, 1 means Tuesday and so on).
int$interval(optional)-The interval at which log rotations happen. See also the documentation for the $when parameter for more information on how the two parameters interact with each other. The default for both this parameter and $when means that the log rotation will take place every hour.
int$backupCount(optional) Specifies how many backup logs are kept alongside the current log file. Backup logs are named after the date and time at which they were created. The exact format depends on the value of the $when parameter. The default value is 0, which disables deletion of old backups.
bool$delay(optional) Whether to delay the actual opening of the file until the first write. Defaults to false (no delay).
bool$utcWhether the dates and times used in the backups' name should use UTC (true) or local time (false).

Definition at line 118 of file TimedRotatingFile.php.

References Plop\Handler\TimedRotatingFile\$backupCount, Plop\Handler\TimedRotatingFile\$interval, Plop\Handler\TimedRotatingFile\$utc, Plop\Handler\TimedRotatingFile\$when, Plop\Handler\TimedRotatingFile\computeRollover(), and Plop\Handler\TimedRotatingFile\getTime().

Member Function Documentation

Plop\Handler\TimedRotatingFile::computeRollover (   $currentTime)
protected

Determine when the next log rotation should take place.

Parameters
int$currentTimeCurrent time, as a UNIX timestamp.
Return values
intUNIX timestamp for the next log rotation.

Definition at line 204 of file TimedRotatingFile.php.

References Plop\Handler\TimedRotatingFile\$interval.

Referenced by Plop\Handler\TimedRotatingFile\__construct(), and Plop\Handler\TimedRotatingFile\doRollover().

Plop\Handler\TimedRotatingFile::doRollover ( )
protected

Do the actual file rotation.

Returns
This method does not return any value.

Definition at line 278 of file TimedRotatingFile.php.

References Plop\Handler\TimedRotatingFile\$interval, Plop\Handler\TimedRotatingFile\computeRollover(), Plop\Handler\TimedRotatingFile\getFilesToDelete(), and Plop\Handler\File\open().

Plop\Handler\TimedRotatingFile::getFilesToDelete ( )
protected

Return a list of old log files to delete.

Return values
arrayList of old log files to delete.

Definition at line 245 of file TimedRotatingFile.php.

References Plop\Handler\TimedRotatingFile\$suffix.

Referenced by Plop\Handler\TimedRotatingFile\doRollover().

Plop\Handler\TimedRotatingFile::getTime ( )
protected

Return the current time, as a UNIX timestamp.

Return values
intCurrent time, as a UNIX timestamp.

Definition at line 228 of file TimedRotatingFile.php.

Referenced by Plop\Handler\TimedRotatingFile\__construct(), and Plop\Handler\TimedRotatingFile\shouldRollover().

Plop\Handler\TimedRotatingFile::shouldRollover ( \Plop\RecordInterface  $record)
protected

Definition at line 234 of file TimedRotatingFile.php.

References Plop\Handler\TimedRotatingFile\getTime().

Member Data Documentation

Plop\Handler\TimedRotatingFile::$dayNames
staticprotected
Initial value:
= array(
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday'
)

The names of days in English, starting with Monday.

Definition at line 56 of file TimedRotatingFile.php.


The documentation for this class was generated from the following file: