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#
| Method | Description |
|---|---|
__construct | Creates a logger. |
log | Logs with an arbitrary level. |
emergency | System is unusable. |
alert | Action must be taken immediately. |
critical | Critical conditions. |
error | Runtime errors that do not require immediate action but should typically be logged and monitored. |
warning | Exceptional occurrences that are not errors. |
notice | Normal but significant events. |
info | Interesting events. |
debug | Detailed debug information. |
Examples#
$logger = new ConsoleLogger(); // STDERR, every level
$logger = new ConsoleLogger(new Console(STDOUT), 'warning'); // warning and up
$logger->error('disk {path} is full', ['path' => '/var']);