‪TYPO3CMS  ‪main
TYPO3\CMS\Core\Log\Writer\RotatingFileWriter Class Reference
Inheritance diagram for TYPO3\CMS\Core\Log\Writer\RotatingFileWriter:
TYPO3\CMS\Core\Log\Writer\FileWriter TYPO3\CMS\Core\Log\Writer\AbstractWriter TYPO3\CMS\Core\Log\Writer\WriterInterface

Public Member Functions

 __construct (array $options=[])
 
 setLogFile (string $relativeLogFile)
 
 writeLog (LogRecord $record)
 
- ‪Public Member Functions inherited from ‪TYPO3\CMS\Core\Log\Writer\FileWriter
 __destruct ()
 
 setLogFileInfix (string $infix)
 
 getLogFile ()
 

Protected Member Functions

 setInterval (string|Interval $interval)
 
 setMaxFiles (int $maxFiles)
 
 rotate ()
 
 getLastRotation ()
 
 determineNextRotation ()
 
 needsRotation ()
 
 updateRuntimeRotationState (\DateTimeImmutable $lastRotation)
 
- ‪Protected Member Functions inherited from ‪TYPO3\CMS\Core\Log\Writer\FileWriter
 openLogFile ()
 
 closeLogFile ()
 
 createLogFile ()
 
 createHtaccessFile ($htaccessFile)
 
string getDefaultLogFileName ()
 
- ‪Protected Member Functions inherited from ‪TYPO3\CMS\Core\Log\Writer\AbstractWriter
 interpolate (string $message, array $context=[])
 
 formatContextValue (string $value)
 
 formatException (\Throwable $ex)
 

Private Attributes

const ROTATION_DATE_FORMAT = 'YmdHis'
 
Interval $interval = Interval::DAILY
 
int $maxFiles = 5
 
DateTimeImmutable $lastRotation
 
DateTimeImmutable $nextRotation
 

Additional Inherited Members

- ‪Protected Attributes inherited from ‪TYPO3\CMS\Core\Log\Writer\FileWriter
string $logFile = ''
 
string $logFileInfix = ''
 
string $defaultLogFileTemplate = '/log/typo3_%s.log'
 
- ‪Static Protected Attributes inherited from ‪TYPO3\CMS\Core\Log\Writer\FileWriter
static array $logFileHandles = []
 
static array $logFileHandlesCount = []
 

Detailed Description

Write logs into files while providing basic rotation capabilities. This is a very basic approach, suitable for environments where established tools like logrotate are not available.

Definition at line 32 of file RotatingFileWriter.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Log\Writer\RotatingFileWriter::__construct ( array  $options = [])

Constructor, opens the log file handle

Reimplemented from TYPO3\CMS\Core\Log\Writer\FileWriter.

Definition at line 41 of file RotatingFileWriter.php.

Member Function Documentation

◆ determineNextRotation()

TYPO3\CMS\Core\Log\Writer\RotatingFileWriter::determineNextRotation ( )
protected

◆ getLastRotation()

TYPO3\CMS\Core\Log\Writer\RotatingFileWriter::getLastRotation ( )
protected

◆ needsRotation()

TYPO3\CMS\Core\Log\Writer\RotatingFileWriter::needsRotation ( )
protected

Check if log files need to be rotated under following conditions:

1. a) either the next rotation is due b) logs were never rotated before

  1. ‪the log file is not empty - FileWriter::setLogFile() creates one if missing

Definition at line 158 of file RotatingFileWriter.php.

Referenced by TYPO3\CMS\Core\Log\Writer\RotatingFileWriter\writeLog().

◆ rotate()

TYPO3\CMS\Core\Log\Writer\RotatingFileWriter::rotate ( )
protected

This method rotates all log files found by using glob() to take all already rotated logs into account, even after a configuration change.

Log files are rotated using the "copytruncate" approach: the current open log file is copied as-is to a new location, the current log file gets flushed afterward. This way, file handles don't need to get re-created.

Definition at line 103 of file RotatingFileWriter.php.

References TYPO3\CMS\Core\Log\Writer\RotatingFileWriter\updateRuntimeRotationState().

Referenced by TYPO3\CMS\Core\Log\Writer\RotatingFileWriter\writeLog().

◆ setInterval()

TYPO3\CMS\Core\Log\Writer\RotatingFileWriter::setInterval ( string|Interval  $interval)
protected

Internal setter called by FileWriter constructor

Definition at line 58 of file RotatingFileWriter.php.

References TYPO3\CMS\Core\Log\Writer\RotatingFileWriter\$interval.

◆ setLogFile()

TYPO3\CMS\Core\Log\Writer\RotatingFileWriter::setLogFile ( string  $relativeLogFile)

Sets the path to the log file.

Parameters
string$relativeLogFile‪path to the log file, relative to public web dir
Returns
WriterInterface
Exceptions
InvalidLogWriterConfigurationException

Reimplemented from TYPO3\CMS\Core\Log\Writer\FileWriter.

Definition at line 46 of file RotatingFileWriter.php.

References TYPO3\CMS\Core\Log\Writer\RotatingFileWriter\getLastRotation(), and TYPO3\CMS\Core\Log\Writer\RotatingFileWriter\updateRuntimeRotationState().

◆ setMaxFiles()

TYPO3\CMS\Core\Log\Writer\RotatingFileWriter::setMaxFiles ( int  $maxFiles)
protected

Internal setter called by FileWriter constructor

Definition at line 71 of file RotatingFileWriter.php.

References TYPO3\CMS\Core\Log\Writer\RotatingFileWriter\$maxFiles.

◆ updateRuntimeRotationState()

◆ writeLog()

Member Data Documentation

◆ $interval

Interval TYPO3\CMS\Core\Log\Writer\RotatingFileWriter::$interval = Interval::DAILY
private

◆ $lastRotation

DateTimeImmutable TYPO3\CMS\Core\Log\Writer\RotatingFileWriter::$lastRotation
private

◆ $maxFiles

int TYPO3\CMS\Core\Log\Writer\RotatingFileWriter::$maxFiles = 5
private

◆ $nextRotation

DateTimeImmutable TYPO3\CMS\Core\Log\Writer\RotatingFileWriter::$nextRotation
private

Definition at line 39 of file RotatingFileWriter.php.

◆ ROTATION_DATE_FORMAT

const TYPO3\CMS\Core\Log\Writer\RotatingFileWriter::ROTATION_DATE_FORMAT = 'YmdHis'
private

Definition at line 34 of file RotatingFileWriter.php.