3 namespace MediaWiki\Logger
;
5 use Psr\Log\NullLogger
;
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
16 class ConsoleSpi
implements Spi
{
18 /** @var string[]|null Channel allow-list: channel name => minimum level */
19 private ?
array $channels;
21 private ?Spi
$forwardTo;
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;
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 );
41 return $this->forwardTo ?
$this->forwardTo
->getLogger( $channel ) : new NullLogger();