MonologSpi: add support for customizing Monolog\Logger instances
authorBryan Davis <bd808@wikimedia.org>
Sun, 25 Oct 2015 21:39:44 +0000 (15:39 -0600)
committerOri.livneh <ori@wikimedia.org>
Wed, 4 Nov 2015 18:07:19 +0000 (18:07 +0000)
Proposed upstream changes to Monolog\Logger will require an ability to
call setter methods on newly created Logger instances to tune them for
use in high volume logging situations. Adding support for making these
types of adjustments to MediaWiki's Monolog integration will benefit
users of the updated library when they land upstream.

Arbitrary setters are called by adding a 'calls' array to the logger
specification. This array uses method names as keys and method arguments
as values. This syntax mirrors the setter invocation behavior of
ObjectFactory with the notable omission of Closure expansion in the
argument list before calling the Logger's setter method.

Bug: T116550
Change-Id: I990c7f00f57451f14954542f5404491b2660a0b7

includes/debug/logger/MonologSpi.php

index 274e18e..685abe0 100644 (file)
@@ -205,6 +205,12 @@ class MonologSpi implements Spi {
        protected function createLogger( $channel, $spec ) {
                $obj = new Logger( $channel );
 
+               if ( isset( $spec['calls'] ) ) {
+                       foreach ( $spec['calls'] as $method => $margs ) {
+                               call_user_func_array( array( $obj, $method ), $margs );
+                       }
+               }
+
                if ( isset( $spec['processors'] ) ) {
                        foreach ( $spec['processors'] as $processor ) {
                                $obj->pushProcessor( $this->getProcessor( $processor ) );