Automatically add a new line at the end of wfLogDBError()
authorAlexandre Emsenhuber <mediawiki@emsenhuber.ch>
Sun, 23 Mar 2014 09:30:59 +0000 (10:30 +0100)
committerAlexandre Emsenhuber <mediawiki@emsenhuber.ch>
Sun, 23 Mar 2014 09:30:59 +0000 (10:30 +0100)
I found two calls to wfLogDBError() that do not add a new line
at the end of the message. So instead of adding them to that
entries, I changed wfLogDBError() to automatically put it on
icoming messages; as for wfDebugLog().

Change-Id: Id014b5827a0aeef6873ebf08d78f0a3d7581d63b

includes/GlobalFunctions.php
includes/db/Database.php
includes/db/DatabaseMysqlBase.php
includes/db/LoadBalancer.php

index a6f936f..981a556 100644 (file)
@@ -1109,7 +1109,7 @@ function wfLogDBError( $text ) {
 
                $date = $d->format( 'D M j G:i:s T Y' );
 
-               $text = "$date\t$host\t$wiki\t$text";
+               $text = "$date\t$host\t$wiki\t" . trim( $text ) . "\n";
                wfErrorLog( $text, $wgDBerrorLog );
        }
 }
index 91ab0ca..b811bfc 100644 (file)
@@ -1109,7 +1109,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                                $elapsed = round( microtime( true ) - $wgRequestTime, 3 );
                                if ( $elapsed < 300 ) {
                                        # Not a database error to lose a transaction after a minute or two
-                                       wfLogDBError( "Connection lost and reconnected after {$elapsed}s, query: $sqlx\n" );
+                                       wfLogDBError( "Connection lost and reconnected after {$elapsed}s, query: $sqlx" );
                                }
                                if ( !$hadTrx ) {
                                        # Should be safe to silently retry
@@ -1153,7 +1153,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                        $this->ignoreErrors( $ignore );
                } else {
                        $sql1line = mb_substr( str_replace( "\n", "\\n", $sql ), 0, 5 * 1024 );
-                       wfLogDBError( "$fname\t{$this->mServer}\t$errno\t$error\t$sql1line\n" );
+                       wfLogDBError( "$fname\t{$this->mServer}\t$errno\t$error\t$sql1line" );
                        wfDebug( "SQL ERROR: " . $error . "\n" );
                        throw new DBQueryError( $this, $error, $errno, $sql, $fname );
                }
index 85be31c..7ee03e0 100644 (file)
@@ -93,7 +93,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase {
                        if ( !$error ) {
                                $error = $this->lastError();
                        }
-                       wfLogDBError( "Error connecting to {$this->mServer}: $error\n" );
+                       wfLogDBError( "Error connecting to {$this->mServer}: $error" );
                        wfDebug( "DB connection error\n" .
                                "Server: $server, User: $user, Password: " .
                                substr( $password, 0, 3 ) . "..., error: " . $error . "\n" );
@@ -108,7 +108,7 @@ abstract class DatabaseMysqlBase extends DatabaseBase {
                        $success = $this->selectDB( $dbName );
                        wfRestoreWarnings();
                        if ( !$success ) {
-                               wfLogDBError( "Error selecting database $dbName on server {$this->mServer}\n" );
+                               wfLogDBError( "Error selecting database $dbName on server {$this->mServer}" );
                                wfDebug( "Error selecting database $dbName on server {$this->mServer} " .
                                        "from client host " . wfHostname() . "\n" );
 
index de4c2f5..a1703f0 100644 (file)
@@ -744,13 +744,13 @@ class LoadBalancer {
 
                if ( !is_object( $conn ) ) {
                        // No last connection, probably due to all servers being too busy
-                       wfLogDBError( "LB failure with no last connection. Connection error: {$this->mLastError}\n" );
+                       wfLogDBError( "LB failure with no last connection. Connection error: {$this->mLastError}" );
 
                        // If all servers were busy, mLastError will contain something sensible
                        throw new DBConnectionError( null, $this->mLastError );
                } else {
                        $server = $conn->getProperty( 'mServer' );
-                       wfLogDBError( "Connection error: {$this->mLastError} ({$server})\n" );
+                       wfLogDBError( "Connection error: {$this->mLastError} ({$server})" );
                        $conn->reportConnectionError( "{$this->mLastError} ({$server})" ); // throws DBConnectionError
                }