| 1 | Logger {#debuglogger} |
| 2 | ======= |
| 3 | |
| 4 | MediaWiki.Logger.LoggerFactory implements a [PSR-3] compatible message logging |
| 5 | system. |
| 6 | |
| 7 | Named Psr.Log.LoggerInterface instances can be obtained from the |
| 8 | MediaWiki.Logger.LoggerFactory::getInstance() static method. |
| 9 | MediaWiki.Logger.LoggerFactory expects a class implementing the |
| 10 | MediaWiki.Logger.Spi interface to act as a factory for new |
| 11 | Psr.Log.LoggerInterface instances. |
| 12 | |
| 13 | The "Spi" in MediaWiki.Logger.Spi stands for "service provider interface". An |
| 14 | SPI is an API intended to be implemented or extended by a third party. This |
| 15 | software design pattern is intended to enable framework extension and |
| 16 | replaceable components. It is specifically used in the |
| 17 | MediaWiki.Logger.LoggerFactory service to allow alternate PSR-3 logging |
| 18 | implementations to be easily integrated with MediaWiki. |
| 19 | |
| 20 | The service provider interface allows the backend logging library to be |
| 21 | implemented in multiple ways. The $wgMWLoggerDefaultSpi global provides the |
| 22 | classname of the default MediaWiki.Logger.Spi implementation to be loaded at |
| 23 | runtime. This can either be the name of a class implementing the |
| 24 | MediaWiki.Logger.Spi with a zero argument constructor or a callable that will |
| 25 | return an MediaWiki.Logger.Spi instance. Alternately the |
| 26 | MediaWiki.Logger.LoggerFactory::registerProvider() static method can be called |
| 27 | to inject an MediaWiki.Logger.Spi instance into the LoggerFactory and bypass the |
| 28 | use of the default configuration variable. |
| 29 | |
| 30 | The MediaWiki.Logger.LegacySpi class implements a service provider to generate |
| 31 | MediaWiki.Logger.LegacyLogger instances. The MediaWiki.Logger.LegacyLogger class |
| 32 | implements the PSR-3 logger interface and provides output and configuration |
| 33 | equivalent to the historic logging output of wfDebug, wfDebugLog, wfLogDBError |
| 34 | and wfErrorLog. The MediaWiki.Logger.LegacySpi class is the default service |
| 35 | provider defined in MainConfigSchema.php. It's usage should be transparent for |
| 36 | users who are not ready or do not wish to switch to a alternate logging |
| 37 | platform. |
| 38 | |
| 39 | The MediaWiki.Logger.MonologSpi class implements a service provider to generate |
| 40 | Psr.Log.LoggerInterface instances that use the [Monolog] logging library. See |
| 41 | the PHP docs (or source) for MediaWiki.Logger.MonologSpi for details on the |
| 42 | configuration of this provider. The default configuration installs a null |
| 43 | handler that will silently discard all logging events. The documentation |
| 44 | provided by the class describes a more feature rich logging configuration. |
| 45 | |
| 46 | ## Classes |
| 47 | |
| 48 | * MediaWiki.Logger.LoggerFactory: Factory for Psr.Log.LoggerInterface loggers |
| 49 | * MediaWiki.Logger.Spi: Service provider interface for |
| 50 | MediaWiki.Logger.LoggerFactory |
| 51 | * MediaWiki.Logger.NullSpi: MediaWiki.Logger.Spi for creating instances that |
| 52 | discard all log events |
| 53 | * MediaWiki.Logger.LegacySpi: Service provider for creating |
| 54 | MediaWiki.Logger.LegacyLogger instances |
| 55 | * MediaWiki.Logger.LegacyLogger: PSR-3 logger that mimics the historical output |
| 56 | and configuration of wfDebug, wfErrorLog and other global logging functions. |
| 57 | * MediaWiki.Logger.MonologSpi: MediaWiki.Logger.Spi for creating instances |
| 58 | backed by the monolog logging library |
| 59 | * MediaWiki.Logger.Monolog.LegacyHandler: Monolog handler that replicates the |
| 60 | udp2log and file logging functionality of wfErrorLog() |
| 61 | * MediaWiki.Logger.Monolog.WikiProcessor: Monolog log processor that adds host: |
| 62 | wfHostname() and wiki: WikiMap::getCurrentWikiId() to all records |
| 63 | |
| 64 | ## Globals |
| 65 | |
| 66 | * $wgMWLoggerDefaultSpi: Configure which service provider LoggerFactory will |
| 67 | use for creating logger objects. |
| 68 | |
| 69 | [PSR-3]: https://www.php-fig.org/psr/psr-3/ |
| 70 | [Monolog]: https://github.com/Seldaek/monolog |