Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/311185

Change subject: Avoid MWDebug/wfLogDBError usage in DatabaseBase
......................................................................

Avoid MWDebug/wfLogDBError usage in DatabaseBase

Change-Id: I64895d3f5b9a000d8186ab6a6ffb4b76a7e9ff40
---
M includes/db/Database.php
M includes/db/DatabaseMysqlBase.php
M includes/db/loadbalancer/LBFactoryMW.php
M includes/debug/logger/LegacyLogger.php
4 files changed, 31 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/85/311185/1

diff --git a/includes/db/Database.php b/includes/db/Database.php
index e908824..d236700 100644
--- a/includes/db/Database.php
+++ b/includes/db/Database.php
@@ -998,7 +998,7 @@
                $this->trxProfiler->recordQueryCompletion(
                        $queryProf, $startTime, $isWrite, $this->affectedRows()
                );
-               MWDebug::query( $sql, $fname, $isMaster, $queryRuntime );
+               $this->queryLogger->debug( $commentedSql );
 
                return $ret;
        }
diff --git a/includes/db/DatabaseMysqlBase.php 
b/includes/db/DatabaseMysqlBase.php
index f8737a8..aaa4f74 100644
--- a/includes/db/DatabaseMysqlBase.php
+++ b/includes/db/DatabaseMysqlBase.php
@@ -126,7 +126,7 @@
                        if ( !$error ) {
                                $error = $this->lastError();
                        }
-                       wfLogDBError(
+                       $this->queryLogger->error(
                                "Error connecting to {db_server}: {error}",
                                $this->getLogContext( [
                                        'method' => __METHOD__,
@@ -145,7 +145,7 @@
                        $success = $this->selectDB( $dbName );
                        MediaWiki\restoreWarnings();
                        if ( !$success ) {
-                               wfLogDBError(
+                               $this->queryLogger->error(
                                        "Error selecting database {db_name} on 
server {db_server}",
                                        $this->getLogContext( [
                                                'method' => __METHOD__,
@@ -183,7 +183,7 @@
                        // Use doQuery() to avoid opening implicit transactions 
(DBO_TRX)
                        $success = $this->doQuery( 'SET ' . implode( ', ', $set 
) );
                        if ( !$success ) {
-                               wfLogDBError(
+                               $this->queryLogger->error(
                                        'Error setting MySQL variables on 
server {db_server} (check $wgSQLMode)',
                                        $this->getLogContext( [
                                                'method' => __METHOD__,
@@ -657,7 +657,7 @@
                        // Standard method: use master server ID (works with 
stock pt-heartbeat)
                        $masterInfo = $this->getMasterServerInfo();
                        if ( !$masterInfo ) {
-                               wfLogDBError(
+                               $this->queryLogger->error(
                                        "Unable to query master of {db_server} 
for server ID",
                                        $this->getLogContext( [
                                                'method' => __METHOD__
@@ -680,7 +680,7 @@
                        return max( $nowUnix - $timeUnix, 0.0 );
                }
 
-               wfLogDBError(
+               $this->queryLogger->error(
                        "Unable to find pt-heartbeat row for {db_server}",
                        $this->getLogContext( [
                                'method' => __METHOD__
diff --git a/includes/db/loadbalancer/LBFactoryMW.php 
b/includes/db/loadbalancer/LBFactoryMW.php
index 33c48a5..8eee1df 100644
--- a/includes/db/loadbalancer/LBFactoryMW.php
+++ b/includes/db/loadbalancer/LBFactoryMW.php
@@ -44,8 +44,8 @@
                        'hostname' => wfHostname(),
                        'trxProfiler' => 
Profiler::instance()->getTransactionProfiler(),
                        'replLogger' => LoggerFactory::getInstance( 
'DBReplication' ),
-                       'queryLogger' => LoggerFactory::getInstance( 
'wfLogDBError' ),
-                       'connLogger' => LoggerFactory::getInstance( 
'wfLogDBError' ),
+                       'queryLogger' => LoggerFactory::getInstance( 'DBQuery' 
),
+                       'connLogger' => LoggerFactory::getInstance( 
'DBConnection' ),
                        'perfLogger' => LoggerFactory::getInstance( 
'DBPerformance' ),
                        'errorLogger' => [ MWExceptionHandler::class, 
'logException' ]
                ];
diff --git a/includes/debug/logger/LegacyLogger.php 
b/includes/debug/logger/LegacyLogger.php
index 526b4ab..c1ce6bf 100644
--- a/includes/debug/logger/LegacyLogger.php
+++ b/includes/debug/logger/LegacyLogger.php
@@ -71,6 +71,14 @@
        ];
 
        /**
+        * @var array
+        */
+       protected static $dbChannels = [
+               'DBQuery' => true,
+               'DBConnection' => true
+       ];
+
+       /**
         * @param string $channel
         */
        public function __construct( $channel ) {
@@ -83,11 +91,22 @@
         * @param string|int $level
         * @param string $message
         * @param array $context
+        * @return null
         */
        public function log( $level, $message, array $context = [] ) {
-               if ( self::shouldEmit( $this->channel, $message, $level, 
$context ) ) {
-                       $text = self::format( $this->channel, $message, 
$context );
-                       $destination = self::destination( $this->channel, 
$message, $context );
+               if ( isset( self::$dbChannels[$this->channel] )
+                       && isset( self::$levelMapping[$level] )
+                       && self::$levelMapping[$level] >= LogLevel::ERROR
+               ) {
+                       // Format and write DB errors to the legacy locations
+                       $effectiveChannel = 'wfLogDBError';
+               } else {
+                       $effectiveChannel = $this->channel;
+               }
+
+               if ( self::shouldEmit( $effectiveChannel, $message, $level, 
$context ) ) {
+                       $text = self::format( $effectiveChannel, $message, 
$context );
+                       $destination = self::destination( $effectiveChannel, 
$message, $context );
                        self::emit( $text, $destination );
                }
                if ( !isset( $context['private'] ) || !$context['private'] ) {
@@ -298,6 +317,7 @@
         * @param string $channel
         * @param string $message
         * @param array $context
+        * @return null
         */
        protected static function formatAsWfDebugLog( $channel, $message, 
$context ) {
                $time = wfTimestamp( TS_DB );
@@ -432,7 +452,6 @@
        *
        * @param string $text
        * @param string $file Filename
-       * @throws MWException
        */
        public static function emit( $text, $file ) {
                if ( substr( $file, 0, 4 ) == 'udp:' ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/311185
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I64895d3f5b9a000d8186ab6a6ffb4b76a7e9ff40
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to