Documentation

Stream extends AbstractWriter
in package

Stream log writer class

Tags
category

Pop

author

Nick Sagona, III nick@popphp.org

copyright

Copyright (c) 2009-2026 Nick Sagona, III

license

https://www.popphp.org/license New BSD License

version
5.0.0

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

$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
throws
Exception

__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
string

getLogLimit()

Get log limit

public getLogLimit() : string|null
Return values
string|null

getStream()

Get the underlying stream resource

public getStream() : mixed

hasLogLimit()

Has log limit

public hasLogLimit() : bool
Return values
bool

isWithinLogLimit()

Check if a log level is within the set log level limit

public isWithinLogLimit(string|int $level) : bool
Parameters
$level : string|int
Return values
bool

setLogLimit()

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
AbstractWriter

writeLog()

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
throws
Exception
Return values
Stream

sanitize()

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
string

        
On this page

Search results