From: Timo Tijhof Date: Thu, 4 Jun 2015 03:52:45 +0000 (+0100) Subject: resourceloader: Make ResourceLoader logger aware X-Git-Tag: 1.31.0-rc.0~11173 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/%7B%7B%20url_for%28%27admin_users%27%29%20%7D%7D?a=commitdiff_plain;h=636cc420c61b7cdde8fd5f0abbf73689da0ec39d;p=lhc%2Fweb%2Fwiklou.git resourceloader: Make ResourceLoader logger aware Change-Id: Ifa197cce1906bc0530dfa873dfde91abbe540637 --- diff --git a/includes/OutputPage.php b/includes/OutputPage.php index ba9fcba1e5..2243996ace 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -20,6 +20,8 @@ * @file */ +use MediaWiki\Logger\LoggerFactory; + /** * This class should be covered by a general architecture document which does * not exist as of January 2011. This is one of the Core classes and should @@ -2737,7 +2739,10 @@ class OutputPage extends ContextSource { */ public function getResourceLoader() { if ( is_null( $this->mResourceLoader ) ) { - $this->mResourceLoader = new ResourceLoader( $this->getConfig() ); + $this->mResourceLoader = new ResourceLoader( + $this->getConfig(), + LoggerFactory::getInstance( 'resourceloader' ) + ); } return $this->mResourceLoader; } diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index 5bc9dc3cba..114a34f716 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -22,13 +22,17 @@ * @author Trevor Parscal */ +use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; + /** * Dynamic JavaScript and CSS resource loading system. * * Most of the documentation is on the MediaWiki documentation wiki starting at: * https://www.mediawiki.org/wiki/ResourceLoader */ -class ResourceLoader { +class ResourceLoader implements LoggerAwareInterface { /** @var int */ protected static $filterCacheVersion = 7; @@ -77,6 +81,11 @@ class ResourceLoader { */ protected $blobStore; + /** + * @var LoggerInterface + */ + private $logger; + /** * Load information stored in the database about modules. * @@ -188,7 +197,7 @@ class ResourceLoader { } if ( !in_array( $filter, array( 'minify-js', 'minify-css' ) ) ) { - wfDebugLog( 'resourceloader', __METHOD__ . ": Invalid filter: $filter" ); + $this->logger->info( __METHOD__ . ": Invalid filter: $filter" ); return $data; } @@ -212,7 +221,7 @@ class ResourceLoader { $cache->set( $key, $result ); } catch ( Exception $e ) { MWExceptionHandler::logException( $e ); - wfDebugLog( 'resourceloader', __METHOD__ . ": minification failed: $e" ); + $this->logger->info( __METHOD__ . ": minification failed: $e" ); $this->errors[] = self::formatExceptionNoComment( $e ); } } @@ -239,14 +248,18 @@ class ResourceLoader { * Register core modules and runs registration hooks. * @param Config|null $config */ - public function __construct( Config $config = null ) { + public function __construct( Config $config = null, LoggerInterface $logger = null ) { global $IP; - if ( $config === null ) { - wfDebug( __METHOD__ . ' was called without providing a Config instance' ); - $config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' ); + if ( !$logger ) { + $logger = new NullLogger(); } + $this->setLogger( $logger ); + if ( !$config ) { + $this->logger->info( __METHOD__ . ' was called without providing a Config instance' ); + $config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' ); + } $this->config = $config; // Add 'local' source first @@ -276,6 +289,10 @@ class ResourceLoader { return $this->config; } + public function setLogger( LoggerInterface $logger ) { + $this->logger = $logger; + } + /** * @param MessageBlobStore $blobStore * @since 1.25 @@ -633,7 +650,7 @@ class ResourceLoader { // Do not allow private modules to be loaded from the web. // This is a security issue, see bug 34907. if ( $module->getGroup() === 'private' ) { - wfDebugLog( 'resourceloader', __METHOD__ . ": request for private module '$name' denied" ); + $this->logger->info( __METHOD__ . ": request for private module '$name' denied" ); $this->errors[] = "Cannot show private module \"$name\""; continue; } @@ -648,7 +665,7 @@ class ResourceLoader { $this->preloadModuleInfo( array_keys( $modules ), $context ); } catch ( Exception $e ) { MWExceptionHandler::logException( $e ); - wfDebugLog( 'resourceloader', __METHOD__ . ": preloading module info failed: $e" ); + $this->logger->info( __METHOD__ . ": preloading module info failed: $e" ); $this->errors[] = self::formatExceptionNoComment( $e ); } @@ -658,7 +675,7 @@ class ResourceLoader { $versionHash = $this->getCombinedVersion( $context, array_keys( $modules ) ); } catch ( Exception $e ) { MWExceptionHandler::logException( $e ); - wfDebugLog( 'resourceloader', __METHOD__ . ": calculating version hash failed: $e" ); + $this->logger->info( __METHOD__ . ": calculating version hash failed: $e" ); $this->errors[] = self::formatExceptionNoComment( $e ); } @@ -941,8 +958,7 @@ MESSAGE; $blobs = $this->blobStore->get( $this, $modules, $context->getLanguage() ); } catch ( Exception $e ) { MWExceptionHandler::logException( $e ); - wfDebugLog( - 'resourceloader', + $this->logger->info( __METHOD__ . ": pre-fetching blobs from MessageBlobStore failed: $e" ); $this->errors[] = self::formatExceptionNoComment( $e ); @@ -1057,7 +1073,7 @@ MESSAGE; } } catch ( Exception $e ) { MWExceptionHandler::logException( $e ); - wfDebugLog( 'resourceloader', __METHOD__ . ": generating module package failed: $e" ); + $this->logger->info( __METHOD__ . ": generating module package failed: $e" ); $this->errors[] = self::formatExceptionNoComment( $e ); // Respond to client with error-state instead of module implementation diff --git a/includes/resourceloader/ResourceLoaderContext.php b/includes/resourceloader/ResourceLoaderContext.php index 66b4ee218f..8eb5d8b80c 100644 --- a/includes/resourceloader/ResourceLoaderContext.php +++ b/includes/resourceloader/ResourceLoaderContext.php @@ -22,6 +22,8 @@ * @author Roan Kattouw */ +use MediaWiki\Logger\LoggerFactory; + /** * Object passed around to modules which contains information about the state * of a specific loader request @@ -123,7 +125,8 @@ class ResourceLoaderContext { */ public static function newDummyContext() { return new self( new ResourceLoader( - ConfigFactory::getDefaultInstance()->makeConfig( 'main' ) + ConfigFactory::getDefaultInstance()->makeConfig( 'main' ), + LoggerFactory::getInstance( 'resourceloader' ) ), new FauxRequest( array() ) ); } diff --git a/load.php b/load.php index e23180799b..22f62fe9ca 100644 --- a/load.php +++ b/load.php @@ -22,6 +22,8 @@ * @author Trevor Parscal */ +use MediaWiki\Logger\LoggerFactory; + // Bail on old versions of PHP, or if composer has not been run yet to install // dependencies. Using dirname( __FILE__ ) here because __DIR__ is PHP5.3+. require_once dirname( __FILE__ ) . '/includes/PHPVersionCheck.php'; @@ -38,7 +40,10 @@ if ( !$wgRequest->checkUrlExtension() ) { // Respond to resource loading request. // foo()->bar() syntax is not supported in PHP4, and this file needs to *parse* in PHP4. $configFactory = ConfigFactory::getDefaultInstance(); -$resourceLoader = new ResourceLoader( $configFactory->makeConfig( 'main' ) ); +$resourceLoader = new ResourceLoader( + $configFactory->makeConfig( 'main' ), + LoggerFactory::getInstance( 'resourceloader' ) +); $resourceLoader->respond( new ResourceLoaderContext( $resourceLoader, $wgRequest ) ); Profiler::instance()->setTemplated( true );