Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / debug / logger / LegacySpi.php
blob57da3ab7b7e7e70489090ec572d2f19b9b7aebcf
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
21 namespace MediaWiki\Logger;
23 use Psr\Log\LoggerInterface;
25 /**
26 * The default service provider for MediaWiki\Logger\LoggerFactory, which creates
27 * LegacyLogger objects.
29 * Usage:
30 * @code
31 * $wgMWLoggerDefaultSpi = [
32 * 'class' => \MediaWiki\Logger\LegacySpi::class,
33 * ];
34 * @endcode
36 * @since 1.25
37 * @ingroup Debug
38 * @copyright © 2014 Wikimedia Foundation and contributors
40 class LegacySpi implements Spi {
42 /**
43 * @var array
45 protected $singletons = [];
47 /**
48 * Get a logger instance.
50 * @param string $channel Logging channel
51 * @return \Psr\Log\LoggerInterface Logger instance
53 public function getLogger( $channel ) {
54 if ( !isset( $this->singletons[$channel] ) ) {
55 $this->singletons[$channel] = new LegacyLogger( $channel );
57 return $this->singletons[$channel];
60 /**
61 * @internal For use by MediaWikiIntegrationTestCase
62 * @param string $channel
63 * @param LoggerInterface|null $logger
64 * @return LoggerInterface|null
66 public function setLoggerForTest( $channel, ?LoggerInterface $logger = null ) {
67 $ret = $this->singletons[$channel] ?? null;
68 $this->singletons[$channel] = $logger;
69 return $ret;