Add a PSR-3 based logging interface
[lhc/web/wiklou.git] / docs / mwlogger.txt
1 MWLogger implements a PSR-3 [0] compatible message logging system.
2
3 The MWLogger class is actually a thin wrapper around any PSR-3 LoggerInterface
4 implementation. Named MWLogger instances can be obtained from the
5 MWLogger::getInstance() static method. MWLogger expects a class implementing
6 the MWLoggerSpi interface to act as a factory for new MWLogger instances.
7
8 The "Spi" in MWLoggerSpi stands for "service provider interface". An SPI is
9 a API intended to be implemented or extended by a third party. This software
10 design pattern is intended to enable framework extension and replaceable
11 components. It is specifically used in the MWLogger service to allow alternate
12 PSR-3 logging implementations to be easily integrated with MediaWiki.
13
14 The MWLogger::getInstance() static method is the means by which most code
15 acquires an MWLogger instance. This in turn delegates creation of MWLogger
16 instances to a class implementing the MWLoggerSpi service provider interface.
17
18 The service provider interface allows the backend logging library to be
19 implemented in multiple ways. The $wgMWLoggerDefaultSpi global provides the
20 classname of the default MWLoggerSpi implementation to be loaded at runtime.
21 This can either be the name of a class implementing the MWLoggerSpi with
22 a zero argument constructor or a callable that will return an MWLoggerSpi
23 instance. Alternately the MWLogger::registerProvider method can be called
24 to inject an MWLoggerSpi instance into MWLogger and bypass the use of this
25 configuration variable.
26
27 The MWLoggerMonologSpi class implements a service provider to generate
28 MWLogger instances that use the Monolog [1] logging library. See the PHP docs
29 (or source) for MWLoggerMonologSpi for details on the configuration of this
30 provider. The default configuration installs a null handler that will silently
31 discard all logging events. The documentation provided by the class describes
32 a more feature rich logging configuration.
33
34 == Classes ==
35 ; MWLogger
36 : PSR-3 compatible logger that wraps any \Psr\Log\LoggerInterface
37 implementation
38 ; MWLoggerSpi
39 : Service provider interface for MWLogger factories
40 ; MWLoggerNullSpi
41 : MWLoggerSpi for creating instances that discard all log events
42 ; MWLoggerMonologSpi
43 : MWLoggerSpi for creating instances backed by the monolog logging library
44 ; MwLoggerMonologHandler
45 : Monolog handler that replicates the udp2log and file logging
46 functionality of wfErrorLog()
47 ; MwLoggerMonologProcessor
48 : Monolog log processer that adds host: wfHostname() and wiki: wfWikiID()
49 to all records
50
51 == Globals ==
52 ; $wgMWLoggerDefaultSpi
53 : Default service provider interface to use with MWLogger
54 ; $wgMWLoggerMonologSpiConfig
55 : Configuration for MWLoggerMonologSpi describing how to configure the
56 Monolog logger instances.
57
58 [0]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
59 [1]: https://github.com/Seldaek/monolog