MediaWiki  1.28.0
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

 $config
 Configuration for creating new loggers. More...
 
 $singletons
 

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']['\'] 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:

$wgMWLoggerDefaultSpi = [
'class' => '\\\\MediaWiki\\\\Logger\\\\MonologSpi',
'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',
],
'psr' => [
'class' => '\\\\Monolog\\\\Processor\\\\PsrLogMessageProcessor',
],
'pid' => [
'class' => '\\\\Monolog\\\\Processor\\\\ProcessIdProcessor',
],
'uid' => [
'class' => '\\\\Monolog\\\\Processor\\\\UidProcessor',
],
'web' => [
'class' => '\\\\Monolog\\\\Processor\\\\WebProcessor',
],
],
'handlers' => [
'stream' => [
'class' => '\\\\Monolog\\\\Handler\\\\StreamHandler',
'args' => [ 'path/to/your.log' ],
'formatter' => 'line',
],
'redis' => [
'class' => '\\\\Monolog\\\\Handler\\\\RedisHandler',
'args' => [ function() {
$redis = new Redis();
$redis->connect( '127.0.0.1', 6379 );
return $redis;
},
'logstash'
],
'formatter' => 'logstash',
'buffer' => true,
],
'udp2log' => [
'class' => '\\\\MediaWiki\\\\Logger\\\\Monolog\\\\LegacyHandler',
'args' => [
'udp://127.0.0.1:8420/mediawiki
],
'formatter' => 'line',
],
],
'formatters' => [
'line' => [
'class' => '\\\\Monolog\\\\Formatter\\\\LineFormatter',
],
'logstash' => [
'class' => '\\\\Monolog\\\\Formatter\\\\LogstashFormatter',
'args' => [ 'mediawiki', php_uname( 'n' ), null, '', 1 ],
],
],
] ],
];
See also
https://github.com/Seldaek/monolog
Since
1.25
Author
Bryan Davis bd808.nosp@m.@wik.nosp@m.imedi.nosp@m.a.or.nosp@m.g
Note
© 2014 Bryan Davis and Wikimedia Foundation.

Definition at line 116 of file MonologSpi.php.

Constructor & Destructor Documentation

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

Definition at line 132 of file MonologSpi.php.

References MediaWiki\Logger\MonologSpi\mergeConfig().

Member Function Documentation

MediaWiki\Logger\MonologSpi::createLogger (   $channel,
  $spec 
)
protected

Create a logger.

Parameters
string$channelLogger channel
array$specConfiguration
Returns
\Monolog\Logger

Definition at line 200 of file MonologSpi.php.

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

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

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

Create or return cached formatter.

Parameters
string$nameFormatter name
Returns
\Monolog\Formatter\FormatterInterface

Definition at line 264 of file MonologSpi.php.

References $name, and ObjectFactory\getObjectFromSpec().

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

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

Create or return cached handler.

Parameters
string$nameProcessor name
Returns
\Monolog\Handler\HandlerInterface

Definition at line 242 of file MonologSpi.php.

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

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

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.

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

Implements MediaWiki\Logger\Spi.

Definition at line 179 of file MonologSpi.php.

References MediaWiki\Logger\MonologSpi\createLogger().

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

Create or return cached processor.

Parameters
string$nameProcessor name
Returns
callable

Definition at line 228 of file MonologSpi.php.

References $name, and ObjectFactory\getObjectFromSpec().

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

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

Merge additional configuration data into the configuration.

Since
1.26
Parameters
array$configConfiguration data.

Definition at line 143 of file MonologSpi.php.

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

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

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 160 of file MonologSpi.php.

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

Member Data Documentation

array MediaWiki\Logger\MonologSpi::$config
protected

Configuration for creating new loggers.

Definition at line 127 of file MonologSpi.php.

array MediaWiki\Logger\MonologSpi::$singletons
protected

Definition at line 121 of file MonologSpi.php.


The documentation for this class was generated from the following file: