Merge "Remove EpicPupper from en.json authors"
[mediawiki.git] / includes / debug / logger / ConsoleSpi.php
blob4e3c50b3cbfd5dc43b0ab112a417d4d96768a89c
1 <?php
3 namespace MediaWiki\Logger;
5 use Psr\Log\NullLogger;
7 /**
8 * ConsoleLogger service provider for MediaWiki\Logger\LoggerFactory.
10 * This is developed for use in maintenance/eval.php.
12 * @internal For use in MediaWiki core only
13 * @since 1.30
14 * @ingroup Debug
16 class ConsoleSpi implements Spi {
18 /** @var string[]|null Channel allow-list: channel name => minimum level */
19 private ?array $channels;
21 private ?Spi $forwardTo;
23 /**
24 * @param array $config
25 * - channels: (string[]) List of channels to log: channel name => minimum level.
26 * Omit to log everything.
27 * - forwardTo: (Spi) Forward all log messages to this SPI (regardless of whether
28 * ConsoleSpi logs them).
30 public function __construct( array $config = [] ) {
31 $this->channels = $config['channels'] ?? null;
32 $this->forwardTo = $config['forwardTo'] ?? null;
35 /** @inheritDoc */
36 public function getLogger( $channel ) {
37 if ( !$this->channels || isset( $this->channels[$channel] ) ) {
38 return new ConsoleLogger( $channel, $this->channels[$channel] ?? null,
39 $this->forwardTo ? $this->forwardTo->getLogger( $channel ) : null );
40 } else {
41 return $this->forwardTo ? $this->forwardTo->getLogger( $channel ) : new NullLogger();