jenkins-bot has submitted this change and it was merged.

Change subject: Allow limiting Monolog output using legacy settings
......................................................................


Allow limiting Monolog output using legacy settings

Add $useLegacyFilter option to MWLoggerMonologHandler constructor that
will use MWLoggerLegacyLogger::shouldEmit to decide if a given log
message should be emitted.

Bug: T845
Change-Id: If311308faad35348fdc7e85155a1bc16bbf75c85
---
M includes/debug/logger/legacy/Logger.php
M includes/debug/logger/monolog/Handler.php
2 files changed, 26 insertions(+), 6 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/debug/logger/legacy/Logger.php 
b/includes/debug/logger/legacy/Logger.php
index 8c0495a..c67bd7b 100644
--- a/includes/debug/logger/legacy/Logger.php
+++ b/includes/debug/logger/legacy/Logger.php
@@ -77,7 +77,7 @@
         * @return bool True if message should be sent to disk/network, false
         * otherwise
         */
-       protected static function shouldEmit( $channel, $message, $context ) {
+       public static function shouldEmit( $channel, $message, $context ) {
                global $wgDebugLogFile, $wgDBerrorLog, $wgDebugLogGroups;
 
                if ( $channel === 'wfLogDBError' ) {
@@ -102,10 +102,10 @@
                        }
 
                } elseif ( isset( $context['private'] ) && $context['private'] 
) {
-                       // Don't emit if the message didn't match previous 
checks based on the
-                       // channel and the event is marked as private. This 
check discards
-                       // messages sent via wfDebugLog() with dest == 
'private' and no explicit
-                       // wgDebugLogGroups configuration.
+                       // Don't emit if the message didn't match previous 
checks based on
+                       // the channel and the event is marked as private. This 
check
+                       // discards messages sent via wfDebugLog() with dest == 
'private'
+                       // and no explicit wgDebugLogGroups configuration.
                        $shouldEmit = false;
                } else {
                        // Default return value is the the same as the historic 
wfDebug
diff --git a/includes/debug/logger/monolog/Handler.php 
b/includes/debug/logger/monolog/Handler.php
index 02ab309..b2e3012 100644
--- a/includes/debug/logger/monolog/Handler.php
+++ b/includes/debug/logger/monolog/Handler.php
@@ -49,6 +49,12 @@
        protected $uri;
 
        /**
+        * Filter log events using legacy rules
+        * @var bool $useLegacyFilter
+        */
+       protected $useLegacyFilter;
+
+       /**
         * Log sink
         * @var resource $sink
         */
@@ -77,16 +83,30 @@
 
        /**
         * @param string $stream Stream URI
+        * @param bool $useLegacyFilter Filter log events using legacy rules
         * @param int $level Minimum logging level that will trigger handler
         * @param bool $bubble Can handled meesages bubble up the handler stack?
         */
        public function __construct(
-               $stream, $level = \Monolog\Logger::DEBUG, $bubble = true
+               $stream,
+               $useLegacyFilter = false,
+               $level = \Monolog\Logger::DEBUG,
+               $bubble = true
        ) {
                parent::__construct( $level, $bubble );
                $this->uri = $stream;
+               $this->useLegacyFilter = $useLegacyFilter;
        }
 
+       public function isHandling( array $record ) {
+               $levelOk = parent::isHandling( $record );
+               if ( $levelOk && $this->useLegacyFilter ) {
+                       return MWLoggerLegacyLogger::shouldEmit(
+                               $record['channel'], $record['message'], $record
+                       );
+               }
+               return $levelOk;
+       }
 
        /**
         * Open the log sink described by our stream URI.

-- 
To view, visit https://gerrit.wikimedia.org/r/174914
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If311308faad35348fdc7e85155a1bc16bbf75c85
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: BryanDavis <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Chad <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to