Update MWLoggerMonologHandler for Monolog 1.12.0
authorBryan Davis <bd808@wikimedia.org>
Sat, 14 Feb 2015 01:08:21 +0000 (18:08 -0700)
committerBryan Davis <bd808@wikimedia.org>
Sat, 14 Feb 2015 01:12:30 +0000 (18:12 -0700)
Monolog 1.12.0 "fixed" Handler::isHandling() so that instead of a full
log record it is only passed an array with the log event's level.
MWLoggerMonologHandler was relying on a full record to allow inspecting
the channel name and looking for a 'private' flag in the context
information.

Update MWLoggerMonologHandler to do legacy processing checks in
Handler::write() where the full log event is present for inspection.

Bug: T89313
Change-Id: Ia878c2cb6bff47d6b35ff38ba3b7ac2ea5556565

includes/debug/logger/monolog/Handler.php

index 05ac64e..a872d84 100644 (file)
@@ -97,16 +97,6 @@ class MWLoggerMonologHandler extends \Monolog\Handler\AbstractProcessingHandler
                $this->useLegacyFilter = $useLegacyFilter;
        }
 
-       public function isHandling( array $record ) {
-               $levelOk = parent::isHandling( $record );
-               if ( $levelOk && $this->useLegacyFilter ) {
-                       return MWLoggerLegacyLogger::shouldEmit(
-                               $record['channel'], $record['message'], $record['level'], $record
-                       );
-               }
-               return $levelOk;
-       }
-
        /**
         * Open the log sink described by our stream URI.
         */
@@ -183,6 +173,18 @@ class MWLoggerMonologHandler extends \Monolog\Handler\AbstractProcessingHandler
 
 
        protected function write( array $record ) {
+               if ( $this->useLegacyFilter &&
+                       !MWLoggerLegacyLogger::shouldEmit(
+                               $record['channel'], $record['message'],
+                               $record['level'], $record
+               ) ) {
+                       // Do not write record if we are enforcing legacy rules and they
+                       // do not pass this message. This used to be done in isHandling(),
+                       // but Monolog 1.12.0 made a breaking change that removed access
+                       // to the needed channel and context information.
+                       return;
+               }
+
                if ( $this->sink === null ) {
                        $this->openSink();
                }