File
extends AbstractWriter
in package
File log writer class
Tags
Table of Contents
Properties
- $file : string|null
- Log file
- $formatter : FormatterInterface|null
- Formatter, null only when using the legacy xml/json whole-file-rewrite handling
- $limit : string|null
- Log limit, stored as the canonical PSR-3 level string
- $type : string|null
- Log file type
Methods
- __construct() : mixed
- Constructor
- getContext() : string
- Get context for log
- getFile() : string
- Get file
- getFormatter() : FormatterInterface|null
- Get formatter
- getLogLimit() : string|null
- Get log limit
- getType() : string|null
- Get type
- hasLogLimit() : bool
- Has log limit
- isWithinLogLimit() : bool
- Check if a log level is within the set log level limit
- setLogLimit() : AbstractWriter
- Set log limit
- writeLog() : File
- Write to the log
- sanitize() : string
- Strip CR/LF from a value before it's written into a delimited/line-based log format, to prevent an embedded newline from forging a fake extra line (or, for writers that build header-style text like Mail's Subject line, a fake extra header).
- withExclusiveLock() : void
- Run a read-modify-write cycle against the log file under an exclusive lock, to prevent two concurrent writers from racing on file_get_contents()/file_put_contents() and silently losing one writer's entry. $transform receives the file's current content and must return the new content to write back.
Properties
$file
Log file
protected
string|null
$file
= null
$formatter
Formatter, null only when using the legacy xml/json whole-file-rewrite handling
protected
FormatterInterface|null
$formatter
= null
$limit
Log limit, stored as the canonical PSR-3 level string
protected
string|null
$limit
= null
$type
Log file type
protected
string|null
$type
= null
Methods
__construct()
Constructor
public
__construct(string $file[, FormatterInterface|null $formatter = null ]) : mixed
Instantiate the file writer object
Parameters
- $file : string
- $formatter : FormatterInterface|null = null
getContext()
Get context for log
public
getContext([array<string|int, mixed> $context = [] ]) : string
Parameters
- $context : array<string|int, mixed> = []
Return values
stringgetFile()
Get file
public
getFile() : string
Return values
stringgetFormatter()
Get formatter
public
getFormatter() : FormatterInterface|null
Return values
FormatterInterface|nullgetLogLimit()
Get log limit
public
getLogLimit() : string|null
Return values
string|nullgetType()
Get type
public
getType() : string|null
Return values
string|nullhasLogLimit()
Has log limit
public
hasLogLimit() : bool
Return values
boolisWithinLogLimit()
Check if a log level is within the set log level limit
public
isWithinLogLimit(string|int $level) : bool
Parameters
- $level : string|int
Return values
boolsetLogLimit()
Set log limit
public
setLogLimit(string|int $level) : AbstractWriter
Accepts either a PSR-3 level string or a legacy severity int (0-7) for backward compatibility; always normalized and stored as the canonical PSR-3 string.
Parameters
- $level : string|int
Return values
AbstractWriterwriteLog()
Write to the log
public
writeLog(string $level, string $message[, array<string|int, mixed> $context = [] ]) : File
Parameters
- $level : string
- $message : string
- $context : array<string|int, mixed> = []
Return values
Filesanitize()
Strip CR/LF from a value before it's written into a delimited/line-based log format, to prevent an embedded newline from forging a fake extra line (or, for writers that build header-style text like Mail's Subject line, a fake extra header).
protected
sanitize(string $value) : string
Parameters
- $value : string
Return values
stringwithExclusiveLock()
Run a read-modify-write cycle against the log file under an exclusive lock, to prevent two concurrent writers from racing on file_get_contents()/file_put_contents() and silently losing one writer's entry. $transform receives the file's current content and must return the new content to write back.
protected
withExclusiveLock(callable $transform) : void
Parameters
- $transform : callable