5use Psr\Log\AbstractLogger;
6use Psr\Log\LoggerInterface;
8use Wikimedia\Assert\Assert;
16 private const LEVELS = [
19 LogLevel::NOTICE => 2,
20 LogLevel::WARNING => 3,
22 LogLevel::CRITICAL => 5,
24 LogLevel::EMERGENCY => 7,
27 private string $channel;
28 private ?
string $minLevel;
29 private ?LoggerInterface $forwardTo;
38 string $minLevel =
null,
39 LoggerInterface $forwardTo =
null
41 Assert::parameter( $minLevel ===
null || isset( self::LEVELS[$minLevel] ),
'$minLevel',
42 'must be a valid, lowercase PSR-3 log level' );
44 $this->channel = $channel;
45 $this->minLevel = $minLevel;
46 $this->forwardTo = $forwardTo;
52 public function log( $level, $message, array $context = [] ) {
53 if ( !$this->minLevel || self::LEVELS[$level] >= self::LEVELS[$this->minLevel] ) {
54 fwrite( STDERR,
"[$level] " .
57 if ( $this->forwardTo ) {
58 $this->forwardTo->log( $level, $message, $context );