Skip to content

AnsiTextStreamSink

TextStreamSink that colors warning-and-above lines so they stand out in an interactive terminal: yellow = warning red = error bold red = critical/alert/emergency Debug/info/notice are left uncolored — the goal is making problems jump out, not painting every line.

Colors are auto-disabled when NO_COLOR is set (see https://no-color.org) or the destination isn’t a TTY (e.g. output redirected to a file or piped into another program), so this is safe to use as a default dev-console sink without leaking escape codes into redirected output. Pass $colors explicitly to override the auto-detection.

class AnsiTextStreamSink extends TextStreamSink

ExtendsTextStreamSink
SourceLogging/Sink/AnsiTextStreamSink.php

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

ParameterTypeDescription
$streamstring
$minLevelLevel
$categoryOverridesarray``<``string``, Level>
$streamResourcemixed
$colors?``bool

Returns mixed

These come from an ancestor and are documented where they are declared.

MethodDeclared inDescription
emit()AbstractStreamSinkRenders the event through the subclass AnsiTextStreamSink::format() and writes it as one newline-terminated line.
flush()AbstractStreamSinkFlushes the underlying stream if one has been opened.
isEnabled()AbstractStreamSinkWhether this sink accepts an event at $level for $category.