BryanDavis has uploaded a new change for review.

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

Change subject: Enable MWLogger logging for legacy logging methods
......................................................................

Enable MWLogger logging for legacy logging methods

Introduces the $wgUseMWLoggerForLegacyFunctions that enables the use of
the MWLogger PSR-3 logger for legacy global logging functions. When
enabled wfDebug, wfDebugLog and wfLogDBError will route their log
messages to MWLogger instances.

Requires the MWLogger system introduced in I5c82299 and the Composer
managed libraries from Ie667944.

Change-Id: I1e5596d590144fbfdfd5f18bc42cf1ef0dbcac12
---
M includes/DefaultSettings.php
M includes/GlobalFunctions.php
2 files changed, 61 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/41/119941/1

diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index 97cdae8..9653c9d 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -5008,6 +5008,17 @@
 $wgMWLoggerDefaultSpi = 'MWLoggerMonologSpi';
 
 /**
+ * Feature switch to enable use of PSR-3 logger for legacy global logging
+ * functions.
+ *
+ * When enabled wfDebug, wfDebugLog and wfLogDBError will route their log
+ * events to MWLogger instances.
+ *
+ * @since 1.23
+ */
+$wgUseMWLoggerForLegacyFunctions = false;
+
+/**
  * Configuration for MonologFactory logger factory.
  *
  * Default configuration installs a null handler that will silently discard
diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php
index a6f936f..ef06d95 100644
--- a/includes/GlobalFunctions.php
+++ b/includes/GlobalFunctions.php
@@ -933,6 +933,7 @@
  */
 function wfDebug( $text, $dest = 'all' ) {
        global $wgDebugLogFile, $wgProfileOnly, $wgDebugRawPage, 
$wgDebugLogPrefix;
+       global $wgUseMWLoggerForLegacyFunctions;
 
        if ( !$wgDebugRawPage && wfIsDebugRawPage() ) {
                return;
@@ -954,12 +955,22 @@
                MWDebug::debugMsg( $text );
        }
 
-       if ( $wgDebugLogFile != '' && !$wgProfileOnly ) {
-               # Strip unprintables; they can switch terminal modes when 
binary data
-               # gets dumped, which is pretty annoying.
-               $text = preg_replace( '![\x00-\x08\x0b\x0c\x0e-\x1f]!', ' ', 
$text );
-               $text = $wgDebugLogPrefix . $text;
-               wfErrorLog( $text, $wgDebugLogFile );
+       if ( !$wgProfileOnly ) {
+               if ( $wgUseMWLoggerForLegacyFunctions ) {
+                       $log = MWLogger::getInstance( 'wfDebug' );
+                       $ctx = array();
+                       if ( $wgDebugLogPrefix !== '' ) {
+                               $ctx['prefix'] = $wgDebugLogPrefix;
+                       }
+                       $log->debug( trim($text), $ctx );
+
+               } elseif ( $wgDebugLogFile != '' ) {
+                       # Strip unprintables; they can switch terminal modes 
when binary data
+                       # gets dumped, which is pretty annoying.
+                       $text = preg_replace( '![\x00-\x08\x0b\x0c\x0e-\x1f]!', 
' ', $text );
+                       $text = $wgDebugLogPrefix . $text;
+                       wfErrorLog( $text, $wgDebugLogFile );
+               }
        }
 }
 
@@ -1041,7 +1052,7 @@
  *     - false: same as 'private'
  */
 function wfDebugLog( $logGroup, $text, $dest = 'all' ) {
-       global $wgDebugLogGroups;
+       global $wgDebugLogGroups, $wgUseMWLoggerForLegacyFunctions;
 
        $text = trim( $text ) . "\n";
 
@@ -1054,7 +1065,15 @@
 
        if ( !isset( $wgDebugLogGroups[$logGroup] ) ) {
                if ( $dest !== 'private' ) {
-                       wfDebug( "[$logGroup] $text", $dest );
+                       if ( $wgUseMWLoggerForLegacyFunctions ) {
+                               $log = MWLogger::getInstance( $logGroup );
+                               $log->debug( trim($text), array(
+                                       'wiki' => wfWikiID(),
+                                       'host' => wfHostname(),
+                               ) );
+                       } else {
+                               wfDebug( "[$logGroup] $text", $dest );
+                       }
                }
                return;
        }
@@ -1079,7 +1098,16 @@
        $time = wfTimestamp( TS_DB );
        $wiki = wfWikiID();
        $host = wfHostname();
-       wfErrorLog( "$time $host $wiki: $text", $destination );
+       if ( $wgUseMWLoggerForLegacyFunctions ) {
+               $log = MWLogger::getInstance( $destination );
+               $log->debug( trim($text), array(
+                       'wiki' => $wiki,
+                       'host' => $host,
+               ) );
+
+       } else {
+               wfErrorLog( "$time $host $wiki: $text", $destination );
+       }
 }
 
 /**
@@ -1088,10 +1116,10 @@
  * @param string $text database error message.
  */
 function wfLogDBError( $text ) {
-       global $wgDBerrorLog, $wgDBerrorLogTZ;
+       global $wgDBerrorLog, $wgDBerrorLogTZ, $wgUseMWLoggerForLegacyFunctions;
        static $logDBErrorTimeZoneObject = null;
 
-       if ( $wgDBerrorLog ) {
+       if ( $wgDBerrorLog || $wgUseMWLoggerForLegacyFunctions ) {
                $host = wfHostname();
                $wiki = wfWikiID();
 
@@ -1109,8 +1137,17 @@
 
                $date = $d->format( 'D M j G:i:s T Y' );
 
-               $text = "$date\t$host\t$wiki\t$text";
-               wfErrorLog( $text, $wgDBerrorLog );
+               if ( $wgUseMWLoggerForLegacyFunctions ) {
+                       $log = MWLogger::getInstance( 'wfLogDBError' );
+                       $log->error( trim($text), array(
+                               'wiki' => $wiki,
+                               'host' => $host,
+                       ) );
+
+               } else {
+                       $text = "$date\t$host\t$wiki\t$text";
+                       wfErrorLog( $text, $wgDBerrorLog );
+               }
        }
 }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1e5596d590144fbfdfd5f18bc42cf1ef0dbcac12
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: BryanDavis <bda...@wikimedia.org>

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

Reply via email to