Merge "debug: Allow the DBQuery channel to be used"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 30 Oct 2018 04:34:20 +0000 (04:34 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 30 Oct 2018 04:34:20 +0000 (04:34 +0000)
includes/debug/MWDebug.php
includes/debug/logger/LegacyLogger.php

index 2189498..ae7f948 100644 (file)
@@ -349,12 +349,11 @@ class MWDebug {
         * @param string $function
         * @param bool $isMaster
         * @param float $runTime Query run time
-        * @return int ID number of the query to pass to queryTime or -1 if the
-        *  debugger is disabled
+        * @return bool True if debugger is enabled, false otherwise
         */
        public static function query( $sql, $function, $isMaster, $runTime ) {
                if ( !self::$enabled ) {
-                       return -1;
+                       return false;
                }
 
                // Replace invalid UTF-8 chars with a square UTF-8 character
@@ -389,7 +388,7 @@ class MWDebug {
                        'time' => $runTime,
                ];
 
-               return count( self::$query ) - 1;
+               return true;
        }
 
        /**
index 9d0789c..288839b 100644 (file)
@@ -93,18 +93,38 @@ class LegacyLogger extends AbstractLogger {
         * @return null
         */
        public function log( $level, $message, array $context = [] ) {
+               global $wgDBerrorLog;
+
                if ( is_string( $level ) ) {
                        $level = self::$levelMapping[$level];
                }
-               if ( $this->channel === 'DBQuery' && isset( $context['method'] )
-                       && isset( $context['master'] ) && isset( $context['runtime'] )
+               if ( $this->channel === 'DBQuery'
+                       && isset( $context['method'] )
+                       && isset( $context['master'] )
+                       && isset( $context['runtime'] )
                ) {
-                       MWDebug::query( $message, $context['method'], $context['master'], $context['runtime'] );
-                       return; // only send profiling data to MWDebug profiling
+                       // Also give the query information to the MWDebug tools
+                       $enabled = MWDebug::query(
+                               $message,
+                               $context['method'],
+                               $context['master'],
+                               $context['runtime']
+                       );
+                       if ( $enabled ) {
+                               // If we the toolbar was enabled, return early so that we don't
+                               // also log the query to the main debug output.
+                               return;
+                       }
                }
 
+               // If this is a DB-related error, and the site has $wgDBerrorLog
+               // configured, rewrite the channel as wfLogDBError instead.
+               // Likewise, if the site does not use  $wgDBerrorLog, it should
+               // configurable like any other channel via $wgDebugLogGroups
+               // or $wgMWLoggerDefaultSpi.
                if ( isset( self::$dbChannels[$this->channel] )
                        && $level >= self::$levelMapping[LogLevel::ERROR]
+                       && $wgDBerrorLog
                ) {
                        // Format and write DB errors to the legacy locations
                        $effectiveChannel = 'wfLogDBError';