FileWriter extends AbstractWriter

Log writer that writes the log records into a file.

Table of Contents

Properties

$defaultLogFileTemplate  : string
Default log file path
$logFile  : string
Log file path, relative to TYPO3's base project folder
$logFileHandles  : array<string|int, mixed>
Log file handle storage
$logFileHandlesCount  : array<string|int, mixed>
Keep track of used file handles by different fileWriter instances
$logFileInfix  : string

Methods

__construct()  : mixed
Constructor, opens the log file handle
__destruct()  : mixed
Destructor, closes the log file handle
__wakeup()  : mixed
Deny object deserialization.
getLogFile()  : string
Gets the path to the log file.
setLogFile()  : WriterInterface
Sets the path to the log file.
setLogFileInfix()  : mixed
writeLog()  : WriterInterface
Writes the log record
closeLogFile()  : mixed
Closes the log file handle.
createHtaccessFile()  : mixed
Creates .htaccess file inside a new directory to access protect it
createLogFile()  : mixed
Creates the log file with correct permissions and parent directories, if needed
formatContextValue()  : string
Escape or quote a value from the context appropriate for the output.
formatException()  : string
Formats an exception into a string.
getDefaultLogFileName()  : string
Returns the path to the default log file.
interpolate()  : string
Interpolates context values into the message placeholders.
openLogFile()  : mixed
Opens the log file handle

Properties

$defaultLogFileTemplate

Default log file path

protected string $defaultLogFileTemplate = '/log/typo3_%s.log'

$logFile

Log file path, relative to TYPO3's base project folder

protected string $logFile = ''

$logFileHandles

Log file handle storage

protected static array<string|int, mixed> $logFileHandles = []

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

Tags
static

$logFileHandlesCount

Keep track of used file handles by different fileWriter instances

protected static array<string|int, mixed> $logFileHandlesCount = []

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.

$logFileInfix

protected string $logFileInfix = ''

Methods

__construct()

Constructor, opens the log file handle

public __construct([array<string|int, mixed> $options = [] ]) : mixed
Parameters
$options : array<string|int, mixed> = []

Configuration options - depends on the actual log writer

__destruct()

Destructor, closes the log file handle

public __destruct() : mixed

__wakeup()

Deny object deserialization.

public __wakeup() : mixed

getLogFile()

Gets the path to the log file.

public getLogFile() : string
Return values
string

setLogFileInfix()

public setLogFileInfix(string $infix) : mixed
Parameters
$infix : string

closeLogFile()

Closes the log file handle.

protected closeLogFile() : mixed

createHtaccessFile()

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

protected createHtaccessFile(string $htaccessFile) : mixed
Parameters
$htaccessFile : string

Path of .htaccess file

createLogFile()

Creates the log file with correct permissions and parent directories, if needed

protected createLogFile() : mixed

formatContextValue()

Escape or quote a value from the context appropriate for the output.

protected formatContextValue(string $value) : string

Note: In some output cases, escaping should not be done here but later on output, such as if it's being written to a database for later display.

Parameters
$value : string
Return values
string

formatException()

Formats an exception into a string.

protected formatException(Throwable $ex) : string

The format here is nearly the same as just casting an exception to a string, but omits the full class namespace and stack trace, as those get very long.

Parameters
$ex : Throwable
Return values
string

getDefaultLogFileName()

Returns the path to the default log file.

protected getDefaultLogFileName() : string

Uses the defaultLogFileTemplate and replaces the %s placeholder with a short MD5 hash based on a static string and the current encryption key.

Return values
string

interpolate()

Interpolates context values into the message placeholders.

protected interpolate(string $message[, array<string|int, mixed> $context = [] ]) : string
Parameters
$message : string
$context : array<string|int, mixed> = []
Return values
string

openLogFile()

Opens the log file handle

protected openLogFile() : mixed
Tags
throws
RuntimeException

if the log file can't be opened.


        
On this page

Search results