MediaWiki  master
ConsoleSpi.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Logger;
4 
5 use Psr\Log\NullLogger;
6 
10 class ConsoleSpi implements Spi {
11 
13  private ?array $channels;
14 
15  private ?Spi $forwardTo;
16 
24  public function __construct( array $config = [] ) {
25  $this->channels = $config['channels'] ?? null;
26  $this->forwardTo = $config['forwardTo'] ?? null;
27  }
28 
30  public function getLogger( $channel ) {
31  if ( !$this->channels || isset( $this->channels[$channel] ) ) {
32  return new ConsoleLogger( $channel, $this->channels[$channel] ?? null,
33  $this->forwardTo ? $this->forwardTo->getLogger( $channel ) : null );
34  } else {
35  return $this->forwardTo ? $this->forwardTo->getLogger( $channel ) : new NullLogger();
36  }
37  }
38 }
A logger which writes to the terminal.
Simple logger SPI for logging to STDERR.
Definition: ConsoleSpi.php:10
getLogger( $channel)
Get a logger instance.Logging channel \Psr\Log\LoggerInterface Logger instance
Definition: ConsoleSpi.php:30
__construct(array $config=[])
Definition: ConsoleSpi.php:24
Service provider interface for \Psr\Log\LoggerInterface implementation libraries.
Definition: Spi.php:38