5use Psr\Log\AbstractLogger;
6use Psr\Log\LoggerInterface;
8use Wikimedia\Assert\Assert;
23 private const LEVELS = [
26 LogLevel::NOTICE => 2,
27 LogLevel::WARNING => 3,
29 LogLevel::CRITICAL => 5,
31 LogLevel::EMERGENCY => 7,
34 private string $channel;
35 private ?
string $minLevel;
36 private ?LoggerInterface $forwardTo;
45 ?
string $minLevel =
null,
46 ?LoggerInterface $forwardTo =
null
48 Assert::parameter( $minLevel ===
null || isset( self::LEVELS[$minLevel] ),
'$minLevel',
49 'must be a valid, lowercase PSR-3 log level' );
51 $this->channel = $channel;
52 $this->minLevel = $minLevel;
53 $this->forwardTo = $forwardTo;
59 public function log( $level, $message, array $context = [] ) {
60 if ( !$this->minLevel || self::LEVELS[$level] >= self::LEVELS[$this->minLevel] ) {
61 fwrite( STDERR,
"[$level] " .
64 if ( $this->forwardTo ) {
65 $this->forwardTo->log( $level, $message, $context );