Skip to content

AbstractStreamSink

Base for sinks that write one line per event to a stream.

Handles the per-sink minimum level (+ optional per-category overrides, longest-prefix wins) and lazy stream opening. Subclasses implement AbstractStreamSink::format().

abstract class AbstractStreamSink implements SinkInterface

ImplementsSinkInterface
SourceLogging/Sink/AbstractStreamSink.php

public function __construct(Level $minLevel = Quiote\Logging\Level::Debug, array<string, Level> $categoryOverrides = [], string $stream = 'php://stdout', resource|null $streamResource = null): mixed

An already-open writable resource (e.g. for tests), used instead of opening $stream lazily.

ParameterTypeDescription
$minLevelLevelMinimum level this sink accepts by default.
$categoryOverridesarray``<``string``, Level>category-prefix => min level.
$streamstringA stream path (opened lazily, append).
$streamResource`resource““null`

Returns mixed

MethodDescription
emit(LogEvent $event): voidRenders the event through the subclass AbstractStreamSink::format() and writes it as one newline-terminated line.
flush(): voidFlushes the underlying stream if one has been opened.
format(LogEvent $event): stringRender an event to a single line (no trailing newline).
formatPlainLine(LogEvent $event): stringShared human-readable single-line rendering used by TextStreamSink and FileSink (and, via TextStreamSink, AnsiTextStreamSink): 2026-07-01T08:02:55.123Z WARNING Quiote.Routing: no route matched /foo {rid=abc}
formatTimestamp(float $ts): stringFormat a UNIX timestamp (with microseconds) as ISO-8601 UTC with milliseconds, e.g.
[`handle(): resourcenull`](#handle)
isEnabled(Level $level, string $category): boolWhether this sink accepts an event at $level for $category.
writeLine(string $line): void

public function emit(LogEvent $event): void

Renders the event through the subclass AbstractStreamSink::format() and writes it as one newline-terminated line.

The stream is opened on first write when the sink was configured with a path rather than a resource. A stream that cannot be opened, or a write that fails, is silently dropped rather than allowed to break the request that was only trying to log.

ParameterTypeDescription
$eventLogEvent

public function flush(): void

Flushes the underlying stream if one has been opened.

A sink that has never emitted anything holds no handle and does nothing here; it does not open the stream just to flush it.

abstract protected function format(LogEvent $event): string

Render an event to a single line (no trailing newline).

ParameterTypeDescription
$eventLogEvent

Returns string

protected static function formatPlainLine(LogEvent $event): string

Shared human-readable single-line rendering used by TextStreamSink and FileSink (and, via TextStreamSink, AnsiTextStreamSink): 2026-07-01T08:02:55.123Z WARNING Quiote.Routing: no route matched /foo {rid=abc}

ParameterTypeDescription
$eventLogEvent

Returns string

protected static function formatTimestamp(float $ts): string

Format a UNIX timestamp (with microseconds) as ISO-8601 UTC with milliseconds, e.g.

2026-07-01T08:02:55.123Z.

ParameterTypeDescription
$tsfloat

Returns string

protected function handle(): resource|null

Returns resource``|``null

public function isEnabled(Level $level, string $category): bool

Whether this sink accepts an event at $level for $category.

The minimum level is the longest category-prefix override that matches (exact name, or a prefix followed by a dot), falling back to the sink’s default minimum level when none matches. The resolution is memoized per exact category, so repeated calls on the hot path cost a lookup.

ParameterTypeDescription
$levelLevel
$categorystring

Returns bool

protected function writeLine(string $line): void

ParameterTypeDescription
$linestring