From 459c0e28bf8f4b5566e2000d6738cdb9bd779973 Mon Sep 17 00:00:00 2001 From: Bryan Davis Date: Wed, 30 Dec 2015 11:31:56 -0700 Subject: [PATCH] Exclude debug log events marked "private" from MWDebug Respect the "private" context variable for debug log events when passing events from MediaWiki\Logger\LegacyLogger to MWDebug::debugMsg. Passing debug log events marked as private to MWDebug was a regression introduced by the PSR-3 logging system. Restore handling of $dest argument to wfDebug which was removed in 1.25 with the PSR-3 logging conversion. The documentation for $dest = 'log' has also been removed. This third debug log event handling option was not implemented in the PSR-3 logging conversion in 1.25. A follow up change will remove known usage of $dest = 'log' in core. Bug: T122644 Change-Id: Ib1d999b8b54e584e3944b46e9163a700f11c2e72 --- includes/GlobalFunctions.php | 18 ++++++++---------- includes/debug/logger/LegacyLogger.php | 13 +++++++++++-- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index e30b3715cf..47d086b2b1 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1038,7 +1038,12 @@ function wfMatchesDomainList( $url, $domains ) { * @since 1.25 support for additional context data * * @param string $text - * @param string|bool $dest Unused + * @param string|bool $dest Destination of the message: + * - 'all': both to the log and HTML (debug toolbar or HTML comments) + * - 'private': excluded from HTML output + * For backward compatibility, it can also take a boolean: + * - true: same as 'all' + * - false: same as 'private' * @param array $context Additional logging context data */ function wfDebug( $text, $dest = 'all', array $context = array() ) { @@ -1065,6 +1070,7 @@ function wfDebug( $text, $dest = 'all', array $context = array() ) { if ( $wgDebugLogPrefix !== '' ) { $context['prefix'] = $wgDebugLogPrefix; } + $context['private'] = ( $dest === false || $dest === 'private' ); $logger = LoggerFactory::getInstance( 'wfDebug' ); $logger->debug( $text, $context ); @@ -1126,7 +1132,6 @@ function wfDebugMem( $exact = false ) { * @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 * - 'private': only to the specific log if set in $wgDebugLogGroups and * discarded otherwise * For backward compatibility, it can also take a boolean: @@ -1137,17 +1142,10 @@ function wfDebugMem( $exact = false ) { function wfDebugLog( $logGroup, $text, $dest = 'all', array $context = array() ) { - // Turn $dest into a string if it's a boolean (for b/c) - if ( $dest === true ) { - $dest = 'all'; - } elseif ( $dest === false ) { - $dest = 'private'; - } - $text = trim( $text ); $logger = LoggerFactory::getInstance( $logGroup ); - $context['private'] = ( $dest === 'private' ); + $context['private'] = ( $dest === false || $dest === 'private' ); $logger->info( $text, $context ); } diff --git a/includes/debug/logger/LegacyLogger.php b/includes/debug/logger/LegacyLogger.php index ef7d81947c..34ea64135c 100644 --- a/includes/debug/logger/LegacyLogger.php +++ b/includes/debug/logger/LegacyLogger.php @@ -90,8 +90,10 @@ class LegacyLogger 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 ); + if ( !isset( $context['private'] ) || !$context['private'] ) { + // Add to debug toolbar if not marked as "private" + MWDebug::debugMsg( $message, array( 'channel' => $this->channel ) + $context ); + } } /** @@ -116,6 +118,13 @@ class LegacyLogger extends AbstractLogger { // 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 + // messages are not discarded by unset $wgDebugLogGroups channel + // handling below. + $shouldEmit = $wgDebugLogFile != ''; + } elseif ( isset( $wgDebugLogGroups[$channel] ) ) { $logConfig = $wgDebugLogGroups[$channel]; -- 2.20.1