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

Public Member Functions

 __construct (array $options=[])
 
 __destruct ()
 
 setLogFileInfix (string $infix)
 
WriterInterface setLogFile (string $relativeLogFile)
 
 getLogFile ()
 
WriterInterface writeLog (LogRecord $record)
 

Protected Member Functions

 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)
 

Protected Attributes

string $logFile = ''
 
string $logFileInfix = ''
 
string $defaultLogFileTemplate = '/log/typo3_%s.log'
 

Static Protected Attributes

static array $logFileHandles = []
 
static array $logFileHandlesCount = []
 

Detailed Description

Log writer that writes the log records into a file.

Definition at line 28 of file FileWriter.php.

Constructor & Destructor Documentation

◆ __construct()

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

◆ __destruct()

TYPO3\CMS\Core\Log\Writer\FileWriter::__destruct ( )

Destructor, closes the log file handle

Definition at line 81 of file FileWriter.php.

References TYPO3\CMS\Core\Log\Writer\FileWriter\$logFile, and TYPO3\CMS\Core\Log\Writer\FileWriter\closeLogFile().

Member Function Documentation

◆ closeLogFile()

TYPO3\CMS\Core\Log\Writer\FileWriter::closeLogFile ( )
protected

Closes the log file handle.

Definition at line 199 of file FileWriter.php.

Referenced by TYPO3\CMS\Core\Log\Writer\FileWriter\__destruct().

◆ createHtaccessFile()

TYPO3\CMS\Core\Log\Writer\FileWriter::createHtaccessFile (   $htaccessFile)
protected

Creates .htaccess file inside a new directory to access protect it

Parameters
string$htaccessFile‪Path of .htaccess file

Definition at line 240 of file FileWriter.php.

References $GLOBALS, and TYPO3\CMS\Core\Utility\GeneralUtility\writeFile().

Referenced by TYPO3\CMS\Core\Log\Writer\FileWriter\createLogFile().

◆ createLogFile()

◆ getDefaultLogFileName()

string TYPO3\CMS\Core\Log\Writer\FileWriter::getDefaultLogFileName ( )
protected

Returns the path to the default log file. Uses the defaultLogFileTemplate and replaces the s placeholder with a short MD5 hash based on a static string and the current encryption key.

Returns
‪string

Definition at line 268 of file FileWriter.php.

References TYPO3\CMS\Core\Core\Environment\getVarPath().

Referenced by TYPO3\CMS\Core\Log\Writer\FileWriter\__construct().

◆ getLogFile()

TYPO3\CMS\Core\Log\Writer\FileWriter::getLogFile ( )

Gets the path to the log file.

Definition at line 126 of file FileWriter.php.

References TYPO3\CMS\Core\Log\Writer\FileWriter\$logFile.

◆ openLogFile()

TYPO3\CMS\Core\Log\Writer\FileWriter::openLogFile ( )
protected

◆ setLogFile()

WriterInterface TYPO3\CMS\Core\Log\Writer\FileWriter::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 in TYPO3\CMS\Core\Log\Writer\RotatingFileWriter.

Definition at line 104 of file FileWriter.php.

References TYPO3\CMS\Core\Log\Writer\FileWriter\$logFile, TYPO3\CMS\Core\Utility\PathUtility\hasProtocolAndScheme(), TYPO3\CMS\Core\Utility\PathUtility\isAbsolutePath(), and TYPO3\CMS\Core\Log\Writer\FileWriter\openLogFile().

Referenced by TYPO3\CMS\Core\Log\Writer\FileWriter\__construct().

◆ setLogFileInfix()

TYPO3\CMS\Core\Log\Writer\FileWriter::setLogFileInfix ( string  $infix)

Definition at line 92 of file FileWriter.php.

◆ writeLog()

WriterInterface TYPO3\CMS\Core\Log\Writer\FileWriter::writeLog ( LogRecord  $record)

Writes the log record

Parameters
LogRecord$recordLog record
Returns
WriterInterface $this
Exceptions

Implements TYPO3\CMS\Core\Log\Writer\WriterInterface.

Reimplemented in TYPO3\CMS\Core\Log\Writer\RotatingFileWriter.

Definition at line 138 of file FileWriter.php.

References TYPO3\CMS\Webhooks\Message\$record, and TYPO3\CMS\Core\Log\Writer\AbstractWriter\formatException().

Member Data Documentation

◆ $defaultLogFileTemplate

string TYPO3\CMS\Core\Log\Writer\FileWriter::$defaultLogFileTemplate = '/log/typo3_%s.log'
protected

Default log file path

Definition at line 40 of file FileWriter.php.

◆ $logFile

string TYPO3\CMS\Core\Log\Writer\FileWriter::$logFile = ''
protected

◆ $logFileHandles

array TYPO3\CMS\Core\Log\Writer\FileWriter::$logFileHandles = []
staticprotected

Log file handle storage

To avoid concurrent file handles on a the same file when using several FileWriter instances, we share the file handles in a static class variable

Definition at line 50 of file FileWriter.php.

◆ $logFileHandlesCount

array TYPO3\CMS\Core\Log\Writer\FileWriter::$logFileHandlesCount = []
staticprotected

Keep track of used file handles by different fileWriter instances

As the logger gets instantiated by class name but the resources are shared via the static $logFileHandles we need to track usage of file handles to avoid closing handles that are still needed by different instances. Only if the count is zero may the file handle be closed.

Definition at line 61 of file FileWriter.php.

◆ $logFileInfix

string TYPO3\CMS\Core\Log\Writer\FileWriter::$logFileInfix = ''
protected

Definition at line 35 of file FileWriter.php.