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
21 namespace MediaWiki\Logger
;
23 use Psr\Log\LoggerInterface
;
26 * The default service provider for MediaWiki\Logger\LoggerFactory, which creates
27 * LegacyLogger objects.
31 * $wgMWLoggerDefaultSpi = [
32 * 'class' => \MediaWiki\Logger\LegacySpi::class,
38 * @copyright © 2014 Wikimedia Foundation and contributors
40 class LegacySpi
implements Spi
{
45 protected $singletons = [];
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];
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;