Stream
extends AbstractWriter
in package
Stream log writer class
Tags
Table of Contents
Properties
- $formatter : FormatterInterface
- Formatter used to shape each log entry
- $limit : string|null
- Log limit, stored as the canonical PSR-3 level string
- $ownsStream : bool
- Whether this instance opened (and therefore owns/closes) the stream
- $stream : mixed
- The underlying stream resource
Methods
- __construct() : mixed
- Constructor
- __destruct() : mixed
- Destructor
- getContext() : string
- Get context for log
- getFormatter() : FormatterInterface
- Get the formatter
- getLogLimit() : string|null
- Get log limit
- getStream() : mixed
- Get the underlying stream resource
- hasLogLimit() : bool
- Has log limit
- isWithinLogLimit() : bool
- Check if a log level is within the set log level limit
- setLogLimit() : AbstractWriter
- Set log limit
- stderr() : static
- Create a writer targeting php://stderr
- stdout() : static
- Create a writer targeting php://stdout
- writeLog() : Stream
- 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).
Properties
$formatter
Formatter used to shape each log entry
protected
FormatterInterface
$formatter
$limit
Log limit, stored as the canonical PSR-3 level string
protected
string|null
$limit
= null
$ownsStream
Whether this instance opened (and therefore owns/closes) the stream
protected
bool
$ownsStream
= false
$stream
The underlying stream resource
protected
mixed
$stream
= null
Methods
__construct()
Constructor
public
__construct(mixed $stream[, FormatterInterface|null $formatter = null ]) : mixed
Instantiate the stream writer object. Accepts either a stream URL string (opened here with fopen($stream, 'a') and closed automatically when this instance is destroyed) or an already-open stream resource (e.g. the STDOUT/STDERR constants, or a caller-supplied fopen() handle) — in that case, the caller keeps ownership and this writer never closes it.
Parameters
- $stream : mixed
- $formatter : FormatterInterface|null = null
Tags
__destruct()
Destructor
public
__destruct() : mixed
Closes the underlying stream only if this instance opened it itself (i.e. was constructed from a string). A caller-supplied resource (including STDOUT/STDERR) is never closed here.
getContext()
Get context for log
public
getContext([array<string|int, mixed> $context = [] ]) : string
Parameters
- $context : array<string|int, mixed> = []
Return values
stringgetFormatter()
Get the formatter
public
getFormatter() : FormatterInterface
Return values
FormatterInterfacegetLogLimit()
Get log limit
public
getLogLimit() : string|null
Return values
string|nullgetStream()
Get the underlying stream resource
public
getStream() : mixed
hasLogLimit()
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
AbstractWriterstderr()
Create a writer targeting php://stderr
public
static stderr([FormatterInterface|null $formatter = null ]) : static
Parameters
- $formatter : FormatterInterface|null = null
Return values
staticstdout()
Create a writer targeting php://stdout
public
static stdout([FormatterInterface|null $formatter = null ]) : static
Parameters
- $formatter : FormatterInterface|null = null
Return values
staticwriteLog()
Write to the log
public
writeLog(string $level, string $message[, array<string|int, mixed> $context = [] ]) : Stream
Parameters
- $level : string
- $message : string
- $context : array<string|int, mixed> = []
Tags
Return values
Streamsanitize()
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