debug: Reference PSR LoggerInterface instead of Monolog where possible
* Remove conditional test since monolog is, at least as a library, unconditionally available in both test and production context. * Reduce direct usage of Monolog by preferring the PSR interface where possible. Change-Id: Id529cfd54e98697cf3254d2a0b8b1e247fe1b7f3
This commit is contained in:
parent
3e81c118a2
commit
1c9a6c1cfe
3 changed files with 9 additions and 13 deletions
|
|
@ -23,6 +23,7 @@ namespace MediaWiki\Logger;
|
|||
use MediaWiki\Logger\Monolog\BufferHandler;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Logger;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Wikimedia\ObjectFactory\ObjectFactory;
|
||||
|
||||
/**
|
||||
|
|
@ -185,7 +186,7 @@ class MonologSpi implements Spi {
|
|||
* name will return the cached instance.
|
||||
*
|
||||
* @param string $channel Logging channel
|
||||
* @return \Psr\Log\LoggerInterface Logger instance
|
||||
* @return LoggerInterface
|
||||
*/
|
||||
public function getLogger( $channel ) {
|
||||
if ( !isset( $this->singletons['loggers'][$channel] ) ) {
|
||||
|
|
@ -204,9 +205,9 @@ class MonologSpi implements Spi {
|
|||
* Create a logger.
|
||||
* @param string $channel Logger channel
|
||||
* @param array $spec Configuration
|
||||
* @return \Monolog\Logger
|
||||
* @return LoggerInterface
|
||||
*/
|
||||
protected function createLogger( $channel, $spec ) {
|
||||
protected function createLogger( $channel, $spec ): LoggerInterface {
|
||||
$obj = new Logger( $channel );
|
||||
|
||||
if ( isset( $spec['calls'] ) ) {
|
||||
|
|
|
|||
|
|
@ -165,20 +165,17 @@ class LegacyLoggerTest extends MediaWikiIntegrationTestCase {
|
|||
$dest + [ 'level' => LogLevel::CRITICAL ],
|
||||
false,
|
||||
],
|
||||
];
|
||||
|
||||
if ( class_exists( \Monolog\Logger::class ) ) {
|
||||
$tests[] = [
|
||||
[
|
||||
\Monolog\Logger::INFO,
|
||||
$dest + [ 'level' => LogLevel::INFO ],
|
||||
true,
|
||||
];
|
||||
$tests[] = [
|
||||
],
|
||||
[
|
||||
\Monolog\Logger::WARNING,
|
||||
$dest + [ 'level' => LogLevel::EMERGENCY ],
|
||||
false,
|
||||
];
|
||||
}
|
||||
]
|
||||
];
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -165,7 +165,6 @@ class MonologSpiTest extends \MediaWikiUnitTestCase {
|
|||
$logger = $monologSpi->getLogger( 'mychannel' );
|
||||
$wrapperMonologSpi = TestingAccessWrapper::newFromObject( $monologSpi );
|
||||
$this->assertInstanceOf( \Psr\Log\LoggerInterface::class, $logger );
|
||||
$this->assertInstanceOf( \Monolog\Logger::class, $logger );
|
||||
$this->assertCount( 1, $wrapperMonologSpi->singletons['loggers'] );
|
||||
$this->assertArrayHasKey( 'mychannel', $wrapperMonologSpi->singletons['loggers'] );
|
||||
|
||||
|
|
@ -213,7 +212,6 @@ class MonologSpiTest extends \MediaWikiUnitTestCase {
|
|||
$logger = $monologSpi->getLogger( 'emptychannel' );
|
||||
$wrapperMonologSpi = TestingAccessWrapper::newFromObject( $monologSpi );
|
||||
$this->assertInstanceOf( \Psr\Log\LoggerInterface::class, $logger );
|
||||
$this->assertInstanceOf( \Monolog\Logger::class, $logger );
|
||||
$this->assertCount( 1, $wrapperMonologSpi->singletons['loggers'] );
|
||||
$this->assertArrayHasKey( 'emptychannel', $wrapperMonologSpi->singletons['loggers'] );
|
||||
$actualHandlers = $logger->getHandlers();
|
||||
|
|
|
|||
Loading…
Reference in a new issue