MediaWiki  1.28.0
MonologSpi.php
Go to the documentation of this file.
1 <?php
21 namespace MediaWiki\Logger;
22 
26 
116 class MonologSpi implements Spi {
117 
121  protected $singletons;
122 
127  protected $config;
128 
132  public function __construct( array $config ) {
133  $this->config = [];
134  $this->mergeConfig( $config );
135  }
136 
143  public function mergeConfig( array $config ) {
144  foreach ( $config as $key => $value ) {
145  if ( isset( $this->config[$key] ) ) {
146  $this->config[$key] = array_merge( $this->config[$key], $value );
147  } else {
148  $this->config[$key] = $value;
149  }
150  }
151  $this->reset();
152  }
153 
160  public function reset() {
161  $this->singletons = [
162  'loggers' => [],
163  'handlers' => [],
164  'formatters' => [],
165  'processors' => [],
166  ];
167  }
168 
179  public function getLogger( $channel ) {
180  if ( !isset( $this->singletons['loggers'][$channel] ) ) {
181  // Fallback to using the '@default' configuration if an explict
182  // configuration for the requested channel isn't found.
183  $spec = isset( $this->config['loggers'][$channel] ) ?
184  $this->config['loggers'][$channel] :
185  $this->config['loggers']['@default'];
186 
187  $monolog = $this->createLogger( $channel, $spec );
188  $this->singletons['loggers'][$channel] = $monolog;
189  }
190 
191  return $this->singletons['loggers'][$channel];
192  }
193 
200  protected function createLogger( $channel, $spec ) {
201  $obj = new Logger( $channel );
202 
203  if ( isset( $spec['calls'] ) ) {
204  foreach ( $spec['calls'] as $method => $margs ) {
205  call_user_func_array( [ $obj, $method ], $margs );
206  }
207  }
208 
209  if ( isset( $spec['processors'] ) ) {
210  foreach ( $spec['processors'] as $processor ) {
211  $obj->pushProcessor( $this->getProcessor( $processor ) );
212  }
213  }
214 
215  if ( isset( $spec['handlers'] ) ) {
216  foreach ( $spec['handlers'] as $handler ) {
217  $obj->pushHandler( $this->getHandler( $handler ) );
218  }
219  }
220  return $obj;
221  }
222 
228  public function getProcessor( $name ) {
229  if ( !isset( $this->singletons['processors'][$name] ) ) {
230  $spec = $this->config['processors'][$name];
231  $processor = ObjectFactory::getObjectFromSpec( $spec );
232  $this->singletons['processors'][$name] = $processor;
233  }
234  return $this->singletons['processors'][$name];
235  }
236 
242  public function getHandler( $name ) {
243  if ( !isset( $this->singletons['handlers'][$name] ) ) {
244  $spec = $this->config['handlers'][$name];
246  if ( isset( $spec['formatter'] ) ) {
247  $handler->setFormatter(
248  $this->getFormatter( $spec['formatter'] )
249  );
250  }
251  if ( isset( $spec['buffer'] ) && $spec['buffer'] ) {
253  }
254  $this->singletons['handlers'][$name] = $handler;
255  }
256  return $this->singletons['handlers'][$name];
257  }
258 
264  public function getFormatter( $name ) {
265  if ( !isset( $this->singletons['formatters'][$name] ) ) {
266  $spec = $this->config['formatters'][$name];
267  $formatter = ObjectFactory::getObjectFromSpec( $spec );
268  $this->singletons['formatters'][$name] = $formatter;
269  }
270  return $this->singletons['formatters'][$name];
271  }
272 }
getFormatter($name)
Create or return cached formatter.
Definition: MonologSpi.php:264
the array() calling protocol came about after MediaWiki 1.4rc1.
static getObjectFromSpec($spec)
Instantiate an object based on a specification array.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
mergeConfig(array $config)
Merge additional configuration data into the configuration.
Definition: MonologSpi.php:143
getLogger($channel)
Get a logger instance.
Definition: MonologSpi.php:179
$value
LoggerFactory service provider that creates loggers implemented by Monolog.
Definition: MonologSpi.php:116
__construct(array $config)
Definition: MonologSpi.php:132
$config
Configuration for creating new loggers.
Definition: MonologSpi.php:127
Service provider interface for \Psr\Log\LoggerInterface implementation libraries. ...
Definition: Spi.php:37
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
getProcessor($name)
Create or return cached processor.
Definition: MonologSpi.php:228
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
getHandler($name)
Create or return cached handler.
Definition: MonologSpi.php:242
createLogger($channel, $spec)
Create a logger.
Definition: MonologSpi.php:200
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
Definition: hooks.txt:802
Updates \Monolog\Handler\BufferHandler to use DeferredUpdates rather than register_shutdown_function...
reset()
Reset internal caches.
Definition: MonologSpi.php:160
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:300