Skip to content

FileSink

Plain-text sink that appends one line per event to a file on disk, creating the parent directory if it doesn’t exist yet (AbstractStreamSink’s lazy fopen() would otherwise fail silently against a missing directory).

Same line format as TextStreamSink — deliberately never colorized, since a log file is read by more than terminals (tail | grep, log shippers, etc.) and ANSI escape codes would just be noise there. For a colorized terminal sink use AnsiTextStreamSink.

final class FileSink extends AbstractStreamSink

ExtendsAbstractStreamSink
SourceLogging/Sink/FileSink.php

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

Pre-opened resource, for tests — when supplied, $path is never touched and no directory is created.

ParameterTypeDescription
$pathstringFilesystem path to append to.
$minLevelLevel
$categoryOverridesarray``<``string``, Level>
$streamResource`resource““null`

Returns mixed

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

MethodDeclared inDescription
emit()AbstractStreamSinkRenders the event through the subclass FileSink::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.