MediaWiki master
MediaWiki\Logger\MonologSpi Class Reference

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

Inherits MediaWiki\Logger\Spi.

Collaboration diagram for MediaWiki\Logger\MonologSpi:

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

array array< string, array< string, array > > $config = []
 Configuration for creating new loggers.
 
 array {loggers:LoggerInterface[],handlers:HandlerInterface[],formatters:FormatterInterface[],processors:callable[]} $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']['\@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' => [
'class' => \\Monolog\\Processor\\PsrLogMessageProcessor::class,
],
'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( '127.0.0.1', 6379 );
return $redis;
},
'logstash'
],
'formatter' => 'logstash',
'buffer' => true,
],
'udp2log' => [
'class' => \\MediaWiki\\Logger\\Monolog\\LegacyHandler::class,
'args' => [
'udp://127.0.0.1:8420/mediawiki
],
'formatter' => 'line',
],
],
'formatters' => [
'line' => [
'class' => \\Monolog\\Formatter\\LineFormatter::class,
],
'logstash' => [
'class' => \\Monolog\\Formatter\\LogstashFormatter::class,
'args' => [ 'mediawiki', php_uname( 'n' ), null, '', 1 ],
],
],
] ],
];
$wgMWLoggerDefaultSpi
Config variable stub for the MWLoggerDefaultSpi setting, for use by phpdoc and IDEs.
Generic processor that reads associated arrays and registers whatever is required.
Definition Processor.php:9
A helper class for throttling authentication attempts.
See also
https://github.com/Seldaek/monolog
Since
1.25
Note
© 2014 Wikimedia Foundation and contributors

Definition at line 123 of file MonologSpi.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 139 of file MonologSpi.php.

References MediaWiki\Logger\MonologSpi\mergeConfig().

Member Function Documentation

◆ createLogger()

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

Create a logger.

Parameters
string$channelLogger channel
array$specConfiguration
Returns
LoggerInterface

Definition at line 213 of file MonologSpi.php.

References MediaWiki\Logger\MonologSpi\getHandler().

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

◆ getFormatter()

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

Create or return cached formatter.

Parameters
string$nameFormatter name
Returns
FormatterInterface

Definition at line 295 of file MonologSpi.php.

◆ getHandler()

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

Create or return cached handler.

Parameters
string$nameProcessor name
Returns
HandlerInterface

Definition at line 269 of file MonologSpi.php.

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.

Parameters
string$channelLogging channel
Returns
LoggerInterface

Implements MediaWiki\Logger\Spi.

Definition at line 194 of file MonologSpi.php.

References MediaWiki\Logger\MonologSpi\createLogger().

◆ getProcessor()

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

Create or return cached processor.

Parameters
string$nameProcessor name
Returns
callable

Definition at line 254 of file MonologSpi.php.

◆ mergeConfig()

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

Merge additional configuration data into the configuration.

Since
1.26
Parameters
array$configConfiguration data.

Definition at line 149 of file MonologSpi.php.

References MediaWiki\Logger\MonologSpi\$config, 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 175 of file MonologSpi.php.

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

Member Data Documentation

◆ $config

array array<string,array<string,array> > MediaWiki\Logger\MonologSpi::$config = []
protected

Configuration for creating new loggers.

Definition at line 134 of file MonologSpi.php.

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

◆ array

MediaWiki\Logger\MonologSpi::array {loggers:LoggerInterface[],handlers:HandlerInterface[],formatters:FormatterInterface[],processors:callable[]} $singletons
protected

Definition at line 128 of file MonologSpi.php.


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