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)
1  2 
includes/debug/logger/LegacyLogger.php

@@@ -29,7 -29,7 +29,7 @@@ use Psr\Log\LogLevel
  use UDPTransport;
  
  /**
 - * PSR-3 logger that mimics the historic implementation of MediaWiki's
 + * PSR-3 logger that mimics the historic implementation of MediaWiki's former
   * wfErrorLog logging implementation.
   *
   * This logger is configured by the following global configuration variables:
@@@ -93,18 -93,38 +93,38 @@@ class LegacyLogger extends AbstractLogg
         * @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';
                        // specfied.
                        $shouldEmit = (bool)$wgDBerrorLog;
  
 -              } elseif ( $channel === 'wfErrorLog' ) {
 -                      // All messages on the wfErrorLog channel should be emitted.
 -                      $shouldEmit = true;
 -
                } elseif ( $channel === 'wfDebug' ) {
                        // wfDebug messages are emitted if a catch all logging file has
                        // been specified. Checked explicitly so that 'private' flagged
        /**
         * Format a message.
         *
 -       * Messages to the 'wfDebug', 'wfLogDBError' and 'wfErrorLog' channels
 -       * receive special formatting to mimic the historic output of the functions
 -       * of the same name. All other channel values are formatted based on the
 -       * historic output of the `wfDebugLog()` global function.
 +       * Messages to the 'wfDebug' and 'wfLogDBError' channels receive special formatting to mimic the
 +       * historic output of the functions of the same name. All other channel values are formatted
 +       * based on the historic output of the `wfDebugLog()` global function.
         *
         * @param string $channel
         * @param string $message
                } elseif ( $channel === 'wfLogDBError' ) {
                        $text = self::formatAsWfLogDBError( $channel, $message, $context );
  
 -              } elseif ( $channel === 'wfErrorLog' ) {
 -                      $text = "{$message}\n";
 -
                } elseif ( $channel === 'profileoutput' ) {
                        // Legacy wfLogProfilingData formatitng
                        $forward = '';