Send messages logged via MWLoggerLegacyLogger::log() to the debug toolbar
authorKunal Mehta <legoktm@gmail.com>
Wed, 18 Mar 2015 22:42:23 +0000 (15:42 -0700)
committerBryanDavis <bdavis@wikimedia.org>
Wed, 18 Mar 2015 23:57:47 +0000 (23:57 +0000)
Bug: T93145
Change-Id: Ia96525faf4ffcbd2b5beae9716d6be009f2b6074

includes/GlobalFunctions.php
includes/debug/MWDebug.php
includes/debug/logger/legacy/Logger.php

index 9ae6cb8..47e7a15 100644 (file)
@@ -1030,12 +1030,7 @@ function wfMatchesDomainList( $url, $domains ) {
  * @since 1.25 support for additional context data
  *
  * @param string $text
- * @param string|bool $dest Destination of the message:
- *     - 'all': both to the log and HTML (debug toolbar or HTML comments)
- *     - 'log': only to the log and not in HTML
- *   For backward compatibility, it can also take a boolean:
- *     - true: same as 'all'
- *     - false: same as 'log'
+ * @param string|bool $dest Unused
  * @param array $context Additional logging context data
  */
 function wfDebug( $text, $dest = 'all', array $context = array() ) {
@@ -1046,13 +1041,6 @@ function wfDebug( $text, $dest = 'all', array $context = array() ) {
                return;
        }
 
-       // Turn $dest into a string if it's a boolean (for b/c)
-       if ( $dest === true ) {
-               $dest = 'all';
-       } elseif ( $dest === false ) {
-               $dest = 'log';
-       }
-
        $text = trim( $text );
 
        // Inline logic from deprecated wfDebugTimer()
@@ -1067,16 +1055,6 @@ function wfDebug( $text, $dest = 'all', array $context = array() ) {
                );
        }
 
-       if ( $dest === 'all' ) {
-               $prefix = '';
-               if ( $wgDebugTimestamps ) {
-                       // Prepend elapsed request time and real memory usage with two
-                       // trailing spaces.
-                       $prefix = "{$context['seconds_elapsed']} {$context['memory_used']}  ";
-               }
-               MWDebug::debugMsg( "{$prefix}{$text}" );
-       }
-
        if ( $wgDebugLogPrefix !== '' ) {
                $context['prefix'] = $wgDebugLogPrefix;
        }
@@ -1181,10 +1159,6 @@ function wfDebugLog(
 
        $text = trim( $text );
 
-       if ( $dest === 'all' ) {
-               MWDebug::debugMsg( "[{$logGroup}] {$text}\n" );
-       }
-
        $logger = MWLoggerFactory::getInstance( $logGroup );
        $context['private'] = ( $dest === 'private' );
        $logger->info( $text, $context );
index 48d4e8d..dc80a46 100644 (file)
@@ -309,11 +309,24 @@ class MWDebug {
         *
         * @since 1.19
         * @param string $str
+        * @param array $context
         */
-       public static function debugMsg( $str ) {
+       public static function debugMsg( $str, $context = array() ) {
                global $wgDebugComments, $wgShowDebug;
 
                if ( self::$enabled || $wgDebugComments || $wgShowDebug ) {
+                       if ( $context ) {
+                               $prefix = '';
+                               if ( isset( $context['prefix'] ) ) {
+                                       $prefix = $context['prefix'];
+                               } elseif ( isset( $context['channel'] ) && $context['channel'] !== 'wfDebug' ) {
+                                       $prefix = "[{$context['channel']}] ";
+                               }
+                               if ( isset( $context['seconds_elapsed'] ) && isset( $context['memory_used'] ) ) {
+                                       $prefix .= "{$context['seconds_elapsed']} {$context['memory_used']}  ";
+                               }
+                               $str = $prefix . $str;
+                       }
                        self::$debug[] = rtrim( UtfNormal::cleanUp( $str ) );
                }
        }
index be46c27..c53aeaa 100644 (file)
@@ -84,6 +84,8 @@ class MWLoggerLegacyLogger extends AbstractLogger {
                        $destination = self::destination( $this->channel, $message, $context );
                        self::emit( $text, $destination );
                }
+               // Add to debug toolbar
+               MWDebug::debugMsg( $message, array( 'channel' => $this->channel ) + $context );
        }