MediaWiki  REL1_31
MediaWiki\Logger\MonologSpi Class Reference

LoggerFactory service provider that creates loggers implemented by Monolog. More...

Inheritance diagram for MediaWiki\Logger\MonologSpi:
Collaboration diagram for MediaWiki\Logger\MonologSpi:

Public Member Functions

 __construct (array $config)
 getFormatter ( $name)
 Create or return cached formatter. More...
 getHandler ( $name)
 Create or return cached handler. More...
 getLogger ( $channel)
 Get a logger instance. More...
 getProcessor ( $name)
 Create or return cached processor. More...
 mergeConfig (array $config)
 Merge additional configuration data into the configuration. More...
 reset ()
 Reset internal caches. More...

Protected Member Functions

 createLogger ( $channel, $spec)
 Create a logger. More...

Protected Attributes

 Configuration for creating new loggers. More...

Detailed Description

LoggerFactory service provider that creates loggers implemented by Monolog.

Configured using an array of configuration data with the keys 'loggers', 'processors', 'handlers' and 'formatters'.

The ['loggers']['\@default'] configuration will be used to create loggers for any channel that isn't explicitly named in the 'loggers' configuration section.

Configuration will most typically be provided in the $wgMWLoggerDefaultSpi global configuration variable used by LoggerFactory to construct its default SPI provider:

'class' => \\MediaWiki\\Logger\\MonologSpi::class,
'args' => [ [
'loggers' => [
'@default' => [
'processors' => [ 'wiki', 'psr', 'pid', 'uid', 'web' ],
'handlers' => [ 'stream' ],
'runJobs' => [
'processors' => [ 'wiki', 'psr', 'pid' ],
'handlers' => [ 'stream' ],
'processors' => [
'wiki' => [
'class' => \\MediaWiki\\Logger\\Monolog\\WikiProcessor::class,
'psr' => [
'pid' => [
'class' => \\Monolog\\Processor\\ProcessIdProcessor::class,
'uid' => [
'class' => \\Monolog\\Processor\\UidProcessor::class,
'web' => [
'class' => \\Monolog\\Processor\\WebProcessor::class,
'handlers' => [
'stream' => [
'class' => \\Monolog\\Handler\\StreamHandler::class,
'args' => [ 'path/to/your.log' ],
'formatter' => 'line',
'redis' => [
'class' => \\Monolog\\Handler\\RedisHandler::class,
'args' => [ function() {
$redis = new Redis();
$redis->connect( '', 6379 );
return $redis;
'formatter' => 'logstash',
'buffer' => true,
'udp2log' => [
'class' => \\MediaWiki\\Logger\\Monolog\\LegacyHandler::class,
'args' => [
'formatter' => 'line',
'formatters' => [
'line' => [
'class' => \\Monolog\\Formatter\\LineFormatter::class,
'logstash' => [
'class' => \\Monolog\\Formatter\\LogstashFormatter::class,
'args' => [ 'mediawiki', php_uname( 'n' ), null, '', 1 ],
] ],
See also
© 2014 Wikimedia Foundation and contributors

Definition at line 115 of file MonologSpi.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Logger\MonologSpi::__construct ( array  $config)
array$configConfiguration data.

Definition at line 131 of file MonologSpi.php.

References MediaWiki\Logger\MonologSpi\mergeConfig().

Member Function Documentation

◆ createLogger()

MediaWiki\Logger\MonologSpi::createLogger (   $channel,

Create a logger.

string$channelLogger channel

Definition at line 199 of file MonologSpi.php.

References $handler, as, MediaWiki\Logger\MonologSpi\getHandler(), and MediaWiki\Logger\MonologSpi\getProcessor().

Referenced by MediaWiki\Logger\MonologSpi\getLogger().

◆ getFormatter()

MediaWiki\Logger\MonologSpi::getFormatter (   $name)

Create or return cached formatter.

string$nameFormatter name

Definition at line 263 of file MonologSpi.php.

References $name.

Referenced by MediaWiki\Logger\MonologSpi\getHandler().

◆ getHandler()

MediaWiki\Logger\MonologSpi::getHandler (   $name)

Create or return cached handler.

string$nameProcessor name

Definition at line 241 of file MonologSpi.php.

References $handler, $name, and MediaWiki\Logger\MonologSpi\getFormatter().

Referenced by MediaWiki\Logger\MonologSpi\createLogger().

◆ getLogger()

MediaWiki\Logger\MonologSpi::getLogger (   $channel)

Get a logger instance.

Creates and caches a logger instance based on configuration found in the $wgMWLoggerMonologSpiConfig global. Subsequent request for the same channel name will return the cached instance.

string$channelLogging channel
\Psr\Log\LoggerInterface Logger instance

Implements MediaWiki\Logger\Spi.

Definition at line 178 of file MonologSpi.php.

References MediaWiki\Logger\MonologSpi\createLogger().

◆ getProcessor()

MediaWiki\Logger\MonologSpi::getProcessor (   $name)

Create or return cached processor.

string$nameProcessor name

Definition at line 227 of file MonologSpi.php.

References $name.

Referenced by MediaWiki\Logger\MonologSpi\createLogger().

◆ mergeConfig()

MediaWiki\Logger\MonologSpi::mergeConfig ( array  $config)

Merge additional configuration data into the configuration.

array$configConfiguration data.

Definition at line 142 of file MonologSpi.php.

References MediaWiki\Logger\MonologSpi\$config, $value, as, and MediaWiki\Logger\MonologSpi\reset().

Referenced by MediaWiki\Logger\MonologSpi\__construct().

◆ reset()

MediaWiki\Logger\MonologSpi::reset ( )

Reset internal caches.

This is public for use in unit tests. Under normal operation there should be no need to flush the caches.

Definition at line 159 of file MonologSpi.php.

Referenced by MediaWiki\Logger\MonologSpi\mergeConfig().

Member Data Documentation

◆ $config

array MediaWiki\Logger\MonologSpi::$config

Configuration for creating new loggers.

Definition at line 126 of file MonologSpi.php.

Referenced by MediaWiki\Logger\MonologSpi\mergeConfig().

◆ $singletons

array MediaWiki\Logger\MonologSpi::$singletons

Definition at line 120 of file MonologSpi.php.

The documentation for this class was generated from the following file:
while(( $__line=Maintenance::readconsole()) !==false) print n
Definition: eval.php:64
Processors read associated arrays and register whatever is required.
Definition: Processor.php:9
Default service provider for creating Psr\Log\LoggerInterface instances.
Definition: DefaultSettings.php:6263
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:56
I won t presume to tell you how to I m just describing the methods I chose to use for myself If you do choose to follow these it will probably be easier for you to collaborate with others on the but if you want to contribute without by all means do which work well I also use K &R brace matching style I know that s a religious issue for so if you want to use a style that puts opening braces on the next line
Definition: design.txt:80
The MediaWiki class is the helper class for the index.php entry point.
Definition: MediaWiki.php:34