| 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. |
| 7 | * |
| 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. |
| 12 | * |
| 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 |
| 17 | * |
| 18 | * @file |
| 19 | */ |
| 20 | |
| 21 | namespace MediaWiki\Logger; |
| 22 | |
| 23 | use Psr\Log\LoggerInterface; |
| 24 | |
| 25 | /** |
| 26 | * The default service provider for MediaWiki\Logger\LoggerFactory, which creates |
| 27 | * LegacyLogger objects. |
| 28 | * |
| 29 | * Usage: |
| 30 | * @code |
| 31 | * $wgMWLoggerDefaultSpi = [ |
| 32 | * 'class' => \MediaWiki\Logger\LegacySpi::class, |
| 33 | * ]; |
| 34 | * @endcode |
| 35 | * |
| 36 | * @since 1.25 |
| 37 | * @ingroup Debug |
| 38 | * @copyright © 2014 Wikimedia Foundation and contributors |
| 39 | */ |
| 40 | class LegacySpi implements Spi { |
| 41 | |
| 42 | /** |
| 43 | * @var array |
| 44 | */ |
| 45 | protected $singletons = []; |
| 46 | |
| 47 | /** |
| 48 | * Get a logger instance. |
| 49 | * |
| 50 | * @param string $channel Logging channel |
| 51 | * @return \Psr\Log\LoggerInterface Logger instance |
| 52 | */ |
| 53 | public function getLogger( $channel ) { |
| 54 | if ( !isset( $this->singletons[$channel] ) ) { |
| 55 | $this->singletons[$channel] = new LegacyLogger( $channel ); |
| 56 | } |
| 57 | return $this->singletons[$channel]; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @internal For use by MediaWikiIntegrationTestCase |
| 62 | * @param string $channel |
| 63 | * @param LoggerInterface|null $logger |
| 64 | * @return LoggerInterface|null |
| 65 | */ |
| 66 | public function setLoggerForTest( $channel, ?LoggerInterface $logger = null ) { |
| 67 | $ret = $this->singletons[$channel] ?? null; |
| 68 | $this->singletons[$channel] = $logger; |
| 69 | return $ret; |
| 70 | } |
| 71 | |
| 72 | } |