25use Monolog\Formatter\FormatterInterface;
26use Monolog\Handler\FormattableHandlerInterface;
27use Monolog\Handler\HandlerInterface;
28use Monolog\Handler\PsrHandler;
29use Monolog\Handler\StreamHandler;
31use Psr\Log\LoggerInterface;
32use Wikimedia\ObjectFactory\ObjectFactory;
128 protected $singletons;
150 foreach (
$config as $key => $value ) {
151 if ( isset( $this->config[$key] ) ) {
152 $this->config[$key] = array_merge( $this->config[$key], $value );
154 $this->config[$key] = $value;
157 if ( !isset( $this->config[
'loggers'][
'@default'] ) ) {
158 $this->config[
'loggers'][
'@default'] = [
159 'handlers' => [
'@default' ],
161 $this->config[
'handlers'][
'@default'] ??= [
162 'class' => StreamHandler::class,
163 'args' => [
'php://stderr', Logger::ERROR ],
176 $this->singletons = [
195 if ( !isset( $this->singletons[
'loggers'][$channel] ) ) {
198 $spec = $this->config[
'loggers'][$channel] ?? $this->config[
'loggers'][
'@default'];
201 $this->singletons[
'loggers'][$channel] = $monolog;
204 return $this->singletons[
'loggers'][$channel];
217 if ( isset( $spec[
'handlers'] ) && $spec[
'handlers'] ) {
218 foreach ( $spec[
'handlers'] as $handler ) {
224 if ( isset( $spec[
'processors'] ) ) {
225 foreach ( $spec[
'processors'] as $processor ) {
232 $obj =
new Logger( $channel, $handlers, $processors,
new DateTimeZone(
'UTC' ) );
235 $legacyLogger =
new LegacyLogger( $channel );
236 $legacyPsrHandler =
new PsrHandler( $legacyLogger );
237 $obj->pushHandler( $legacyPsrHandler );
240 if ( isset( $spec[
'calls'] ) ) {
241 foreach ( $spec[
'calls'] as $method => $margs ) {
242 $obj->$method( ...$margs );
255 if ( !isset( $this->singletons[
'processors'][$name] ) ) {
256 $spec = $this->config[
'processors'][$name];
258 $processor = ObjectFactory::getObjectFromSpec( $spec );
259 $this->singletons[
'processors'][$name] = $processor;
261 return $this->singletons[
'processors'][$name];
270 if ( !isset( $this->singletons[
'handlers'][$name] ) ) {
271 $spec = $this->config[
'handlers'][$name];
273 $handler = ObjectFactory::getObjectFromSpec( $spec );
275 isset( $spec[
'formatter'] ) &&
276 $handler instanceof FormattableHandlerInterface
278 $handler->setFormatter(
279 $this->getFormatter( $spec[
'formatter'] )
282 if ( isset( $spec[
'buffer'] ) && $spec[
'buffer'] ) {
285 $this->singletons[
'handlers'][$name] = $handler;
287 return $this->singletons[
'handlers'][$name];
296 if ( !isset( $this->singletons[
'formatters'][$name] ) ) {
297 $spec = $this->config[
'formatters'][$name];
299 $formatter = ObjectFactory::getObjectFromSpec( $spec );
300 $this->singletons[
'formatters'][$name] = $formatter;
302 return $this->singletons[
'formatters'][$name];
$wgShowDebug
Config variable stub for the ShowDebug setting, for use by phpdoc and IDEs.
$wgDebugToolbar
Config variable stub for the DebugToolbar setting, for use by phpdoc and IDEs.