From f0cd9a8d0e314042f3a501a02c6d35a1e3d9ad19 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 17 Aug 2005 20:07:33 +0000 Subject: [PATCH] * Add ability to break off certain debug topics into additional log files; use $wgDebugLogGroups to configure and wfDebugLog() to log. --- RELEASE-NOTES | 3 +++ includes/DefaultSettings.php | 8 ++++++++ includes/GlobalFunctions.php | 16 ++++++++++++++++ includes/LoadBalancer.php | 8 ++++++-- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index d3016a31a4..379393f928 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -29,6 +29,9 @@ Misc work going on..... * (bug 3170) Page Title failed to obey MediaWiki:Pagetitle. wikititlesuffix was removed * (bug 3177) Estonian date formats not implemented in LanguageEt.php +* Add ability to break off certain debug topics into additional log files; + use $wgDebugLogGroups to configure and wfDebugLog() to log. + === Caveats === diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 301f9a31ac..ab262c0ca0 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -615,6 +615,14 @@ $wgReadOnly = false; $wgLogQueries = false; $wgDebugDumpSql = false; +/** + * Set to an array of log group keys to filenames. + * If set, wfDebugLog() output for that group will go to that file instead + * of the regular $wgDebugLogFile. Useful for enabling selective logging + * in production. + */ +$wgDebugLogGroups = array(); + /** * Whether to show "we're sorry, but there has been a database error" pages. * Displaying errors aids in debugging, but may display information useful diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 383dee5619..8204cad137 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -175,6 +175,22 @@ function wfDebug( $text, $logonly = false ) { } } +/** + * Send a line to a supplementary debug log file, if configured, or main debug log if not. + * $wgDebugLogGroups[$logGroup] should be set to a filename to send to a separate log. + * @param string $logGroup + * @param string $text + */ +function wfDebugLog( $logGroup, $text ) { + global $wgDebugLogGroups, $wgDBname; + if( $text{strlen( $text ) - 1} != "\n" ) $text .= "\n"; + if( isset( $wgDebugLogGroups[$logGroup] ) ) { + @error_log( "$wgDBname: $text", 3, $wgDebugLogGroups[$logGroup] ); + } else { + wfDebug( $text, true ); + } +} + /** * Log for database errors * @param string $text Database error message. diff --git a/includes/LoadBalancer.php b/includes/LoadBalancer.php index c716d39553..4a0bf88452 100644 --- a/includes/LoadBalancer.php +++ b/includes/LoadBalancer.php @@ -140,7 +140,7 @@ class LoadBalancer { return false; } - #wfDebug( var_export( $loads, true ) ); + #wfDebugLog( 'connect', var_export( $loads, true ) ); # Return a random representative of the remainder return $this->pickRandom( $loads ); @@ -183,8 +183,9 @@ class LoadBalancer { $i = $this->pickRandom( $loads ); } } + $serverIndex = $i; if ( $i !== false ) { - wfDebug( "Using reader #$i: {$this->mServers[$i]['host']}...\n" ); + wfDebugLog( 'connect', "Using reader #$i: {$this->mServers[$i]['host']}...\n" ); $this->openConnection( $i ); if ( !$this->isOpen( $i ) ) { @@ -211,7 +212,10 @@ class LoadBalancer { } if ( $sleepTime ) { $totalElapsed += $sleepTime; + $x = "{$this->mServers[$serverIndex]['host']} $sleepTime [$serverIndex]"; + wfProfileIn( "$fname-sleep $x" ); usleep( $sleepTime ); + wfProfileOut( "$fname-sleep $x" ); } } while ( count( $loads ) && !$done && $totalElapsed / 1e6 < $wgDBClusterTimeout ); -- 2.20.1