MediaWiki  1.33.0
LogCapturingSpi.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Logger;
4 
5 use Psr\Log\AbstractLogger;
6 use Psr\Log\LoggerInterface;
7 
13 class LogCapturingSpi implements Spi {
15  private $singletons;
17  private $inner;
19  private $logs = [];
20 
21  public function __construct( Spi $inner ) {
22  $this->inner = $inner;
23  }
24 
28  public function getLogs() {
29  return $this->logs;
30  }
31 
36  public function getLogger( $channel ) {
37  if ( !isset( $this->singletons[$channel] ) ) {
38  $this->singletons[$channel] = $this->createLogger( $channel );
39  }
40  return $this->singletons[$channel];
41  }
42 
46  public function capture( $log ) {
47  $this->logs[] = $log;
48  }
49 
54  private function createLogger( $channel ) {
55  $inner = $this->inner->getLogger( $channel );
56  return new class( $channel, $inner, $this ) extends AbstractLogger {
58  private $channel;
60  private $logger;
62  private $parent;
63 
64  // phpcs:ignore MediaWiki.Usage.NestedFunctions.NestedFunction
65  public function __construct( $channel, LoggerInterface $logger, LogCapturingSpi $parent ) {
66  $this->channel = $channel;
67  $this->logger = $logger;
68  $this->parent = $parent;
69  }
70 
71  // phpcs:ignore MediaWiki.Usage.NestedFunctions.NestedFunction
72  public function log( $level, $message, array $context = [] ) {
73  $this->parent->capture( [
74  'channel' => $this->channel,
75  'level' => $level,
76  'message' => $message,
77  'context' => $context
78  ] );
79  $this->logger->log( $level, $message, $context );
80  }
81  };
82  }
83 }
logs
as see the revision history and logs
Definition: MIT-LICENSE.txt:5
MediaWiki\Logger\LogCapturingSpi
Wraps another spi to capture all logs generated.
Definition: LogCapturingSpi.php:13
MediaWiki\Logger\LogCapturingSpi\$logs
array $logs
Definition: LogCapturingSpi.php:19
MediaWiki\Logger\LogCapturingSpi\capture
capture( $log)
Definition: LogCapturingSpi.php:46
php
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
MediaWiki\Logger
Definition: ConsoleLogger.php:3
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
MediaWiki\Logger\LogCapturingSpi\__construct
__construct(Spi $inner)
Definition: LogCapturingSpi.php:21
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
MediaWiki\Logger\LogCapturingSpi\getLogs
getLogs()
Definition: LogCapturingSpi.php:28
MediaWiki\Logger\Spi\getLogger
getLogger( $channel)
Get a logger instance.
MediaWiki\Logger\LogCapturingSpi\$inner
Spi $inner
Definition: LogCapturingSpi.php:17
$parent
$parent
Definition: pageupdater.txt:71
MediaWiki\Logger\LogCapturingSpi\getLogger
getLogger( $channel)
Definition: LogCapturingSpi.php:36
MediaWiki\Logger\LogCapturingSpi\$singletons
LoggerInterface[] $singletons
Definition: LogCapturingSpi.php:15
MediaWiki\Logger\Spi
Service provider interface for \Psr\Log\LoggerInterface implementation libraries.
Definition: Spi.php:36
MediaWiki\$context
IContextSource $context
Definition: MediaWiki.php:38
MediaWiki\Logger\LogCapturingSpi\createLogger
createLogger( $channel)
Definition: LogCapturingSpi.php:54