Debian Codegraph @

includes/debug/logger/ConsoleSpi.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Logger;
4
5 use Psr\Log\NullLogger;
6
7 /**
8 * ConsoleLogger service provider for MediaWiki\Logger\LoggerFactory.
9 *
10 * This is developed for use in maintenance/eval.php.
11 *
12 * @internal For use in MediaWiki core only
13 * @since 1.30
14 * @ingroup Debug
15 */
16 class ConsoleSpi implements Spi {
17
18 /** @var string[]|null Channel allow-list: channel name => minimum level */
19 private ?array $channels;
20
21 private ?Spi $forwardTo;
22
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).
29 */
30 public function __construct( array $config = [] ) {
31 $this->channels = $config['channels'] ?? null;
32 $this->forwardTo = $config['forwardTo'] ?? null;
33 }
34
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();
42 }
43 }
44 }