From 59c42b90d5ffd38ed1f6b6d34c830be3168599cd Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sun, 23 Mar 2014 10:30:59 +0100 Subject: [PATCH] Automatically add a new line at the end of wfLogDBError() 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 | 2 +- includes/db/Database.php | 4 ++-- includes/db/DatabaseMysqlBase.php | 4 ++-- includes/db/LoadBalancer.php | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index a6f936fa6d..981a556208 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -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 ); } } diff --git a/includes/db/Database.php b/includes/db/Database.php index 91ab0ca4d0..b811bfcd92 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -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 ); } diff --git a/includes/db/DatabaseMysqlBase.php b/includes/db/DatabaseMysqlBase.php index 85be31c920..7ee03e0047 100644 --- a/includes/db/DatabaseMysqlBase.php +++ b/includes/db/DatabaseMysqlBase.php @@ -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" ); diff --git a/includes/db/LoadBalancer.php b/includes/db/LoadBalancer.php index de4c2f56a8..a1703f0633 100644 --- a/includes/db/LoadBalancer.php +++ b/includes/db/LoadBalancer.php @@ -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 } -- 2.20.1