phasync
Console and logging / ConsoleLogger

Class

ConsoleLogger

A PSR-3 logger writing Console::log() lines: to a terminal styled, piped plain.

Introduction#

It satisfies psr/log 1, 2 and 3 alike: untyped parameters where earlier versions have them, void returns as 3 requires.

Class synopsis#

final class ConsoleLogger implements LoggerInterface {
    /* Methods */
    public ConsoleLogger::__construct(
        ?Console $console = null,
        string $level = 'debug',
        string $source = ''
    )
    public ConsoleLogger::log($level, $message, array $context = []): void
    public ConsoleLogger::emergency($message, array $context = []): void
    public ConsoleLogger::alert($message, array $context = []): void
    public ConsoleLogger::critical($message, array $context = []): void
    public ConsoleLogger::error($message, array $context = []): void
    public ConsoleLogger::warning($message, array $context = []): void
    public ConsoleLogger::notice($message, array $context = []): void
    public ConsoleLogger::info($message, array $context = []): void
    public ConsoleLogger::debug($message, array $context = []): void
}

Methods#

MethodDescription
__constructCreates a logger.
logLogs with an arbitrary level.
emergencySystem is unusable.
alertAction must be taken immediately.
criticalCritical conditions.
errorRuntime errors that do not require immediate action but should typically be logged and monitored.
warningExceptional occurrences that are not errors.
noticeNormal but significant events.
infoInteresting events.
debugDetailed debug information.

Examples#

Example 1
$logger = new ConsoleLogger();                                  // STDERR, every level
$logger = new ConsoleLogger(new Console(STDOUT), 'warning');    // warning and up
$logger->error('disk {path} is full', ['path' => '/var']);