* Add ability to break off certain debug topics into additional log files;
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 17 Aug 2005 20:07:33 +0000 (20:07 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 17 Aug 2005 20:07:33 +0000 (20:07 +0000)
  use $wgDebugLogGroups to configure and wfDebugLog() to log.

RELEASE-NOTES
includes/DefaultSettings.php
includes/GlobalFunctions.php
includes/LoadBalancer.php

index d3016a3..379393f 100644 (file)
@@ -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 ===
 
index 301f9a3..ab262c0 100644 (file)
@@ -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
index 383dee5..8204cad 100644 (file)
@@ -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.
index c716d39..4a0bf88 100644 (file)
@@ -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 );