dbErrorLog can now be forced to UTC
authorAntoine Musso <hashar@free.fr>
Fri, 13 Jul 2012 14:53:06 +0000 (16:53 +0200)
committerAntoine Musso <hashar@free.fr>
Fri, 13 Jul 2012 14:56:36 +0000 (16:56 +0200)
$wgDBerrorLog is used to log database error. It is using
$wgLocalTimezone to format the date which might not always be wanted in
a multi Timezone cluster of wiki.

wgDBerrorLogInUTC , when true, will override the Wiki timezone to uses
UTC whenever a database error is logged.

Change-Id: I091d6029272b69db0aefdebfc37896d0a8e8770e

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

index e56cf60..a9bdeb7 100644 (file)
@@ -23,6 +23,8 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki.
 * The user right 'upload_by_url' is no longer given to sysops by default.
   This only affects installations which have $wgAllowCopyUploads set to true.
 * Removed f-prot support from $wgAntivirusSetup.
+* $wgDBerrorLogInUTC to log error in $wgDBerrorLog using an UTC date instead
+  of the wiki timezone set by $wgLocalTimezone.
 
 === New features in 1.20 ===
 * Added TitleIsAlwaysKnown hook which gets called when determining if a page exists.
index eed7d58..c1c73d2 100644 (file)
@@ -1381,6 +1381,11 @@ $wgMasterWaitTimeout = 10;
 
 /** File to log database errors to */
 $wgDBerrorLog = false;
+/**
+ * Override wiki timezone to UTC for wgDBerrorLog
+ * @since 1.20
+ */
+$wgDBerrorLogInUTC = false;
 
 /** When to give an error message */
 $wgDBClusterTimeout = 10;
index 1a21e20..4326229 100644 (file)
@@ -1053,11 +1053,22 @@ function wfDebugLog( $logGroup, $text, $public = true ) {
  * @param $text String: database error message.
  */
 function wfLogDBError( $text ) {
-       global $wgDBerrorLog;
+       global $wgDBerrorLog, $wgDBerrorLogInUtc;
        if ( $wgDBerrorLog ) {
                $host = wfHostname();
                $wiki = wfWikiID();
-               $text = date( 'D M j G:i:s T Y' ) . "\t$host\t$wiki\t$text";
+
+               if( $wgDBerrorLogInUtc ) {
+                       $wikiTimezone = date_default_timezone_get();
+                       date_default_timezone_set( 'UTC' );
+               }
+               $date = date( 'D M j G:i:s T Y' );
+               if( $wgDBerrorLogInUtc ) {
+                       // Restore timezone
+                       date_default_timezone_set( $wikiTimezone );
+               }
+
+               $text = "$date\t$host\t$wiki\t$text";
                wfErrorLog( $text, $wgDBerrorLog );
        }
 }