BryanDavis has uploaded a new change for review.

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

Change subject: Minimal PSR-3 compatible logger layer
......................................................................

Minimal PSR-3 compatible logger layer

Provide a minimal PSR-3 compatible logger layer to make backporting
critical updates from 1.25+ easier. It also serves to allow extensions
that maintain backwards compatibility with the 1.23 LTS releases to
migrate to the new logging system.

Bug: T91653
Change-Id: If385e722c62dc1f989af6fdee404535bad989acc
---
M RELEASE-NOTES-1.23
M includes/AutoLoader.php
A includes/debug/logger/LoggerFactory.php
3 files changed, 152 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/79/203779/1

diff --git a/RELEASE-NOTES-1.23 b/RELEASE-NOTES-1.23
index 2eaa0a5..64bfa57 100644
--- a/RELEASE-NOTES-1.23
+++ b/RELEASE-NOTES-1.23
@@ -1,6 +1,14 @@
 Security reminder: MediaWiki does not require PHP's register_globals. If you
 have it on, turn it '''off''' if you can.
 
+== MediaWiki 1.23.10 ==
+
+This is a security and maintenance release of the MediaWiki 1.23 branch.
+
+== Changes since 1.23.9 ==
+
+* (T91653) Minimal PSR-3 debug logger to support backports from 1.25+.
+
 == MediaWiki 1.23.9 ==
 
 This is a security and maintenance release of the MediaWiki 1.23 branch.
diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php
index dc923f0..6bb889f 100644
--- a/includes/AutoLoader.php
+++ b/includes/AutoLoader.php
@@ -480,6 +480,11 @@
        # includes/debug
        'MWDebug' => 'includes/debug/Debug.php',
 
+       # includes/debug/logger
+       '\\Psr\\Log\\LoggerInterface' => 
'includes/debug/logger/LoggerFactory.php',
+       '\\MediaWiki\\Logger\\Logger' => 
'includes/debug/logger/LoggerFactory.php',
+       '\\MediaWiki\\Logger\\LoggerFactory' => 
'includes/debug/logger/LoggerFactory.php',
+
        # includes/deferred
        'DataUpdate' => 'includes/deferred/DataUpdate.php',
        'DeferrableUpdate' => 'includes/deferred/DeferredUpdates.php',
diff --git a/includes/debug/logger/LoggerFactory.php 
b/includes/debug/logger/LoggerFactory.php
new file mode 100644
index 0000000..e367366
--- /dev/null
+++ b/includes/debug/logger/LoggerFactory.php
@@ -0,0 +1,139 @@
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+namespace Psr\Log;
+
+/**
+ * @link 
https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
+ */
+interface LoggerInterface {
+       public function emergency( $message, array $context = array() );
+       public function alert( $message, array $context = array() );
+       public function critical( $message, array $context = array() );
+       public function error( $message, array $context = array() );
+       public function warning( $message, array $context = array() );
+       public function notice( $message, array $context = array() );
+       public function info( $message, array $context = array() );
+       public function debug( $message, array $context = array() );
+       public function log( $level, $message, array $context = array() );
+}
+
+namespace MediaWiki\Logger;
+
+/**
+ * PSR-3 logger that wraps wfDebugLog() for backwards compatibility.
+ *
+ * @since 1.23.10
+ * @author Bryan Davis <[email protected]>
+ * @copyright © 2015 Bryan Davis and Wikimedia Foundation.
+ */
+class Logger implements \Psr\Log\LoggerInterface {
+
+       /**
+        * @var string $channel
+        */
+       private $channel;
+
+       /**
+        * @param string $channel
+        */
+       public function __construct( $channel ) {
+               $this->channel = $channel;
+       }
+
+       public function emergency( $message, array $context = array() ) {
+               $this->log( 'emergency', $message, $context );
+       }
+
+       public function alert( $message, array $context = array() ) {
+               $this->log( 'alert', $message, $context );
+       }
+
+       public function critical( $message, array $context = array() ) {
+               $this->log( 'critical', $message, $context );
+       }
+
+       public function error( $message, array $context = array() ) {
+               $this->log( 'error', $message, $context );
+       }
+
+       public function warning( $message, array $context = array() ) {
+               $this->log( 'warning', $message, $context );
+       }
+
+       public function notice( $message, array $context = array() ) {
+               $this->log( 'notice', $message, $context );
+       }
+
+       public function info( $message, array $context = array() ) {
+               $this->log( 'info', $message, $context );
+       }
+
+       public function debug( $message, array $context = array() ) {
+               $this->log( 'debug', $message, $context );
+       }
+
+       public function log( $level, $message, array $context = array() ) {
+               \wfDebugLog(
+                       $this->channel, self::interpolate( $message, $context 
), 'log'
+               );
+       }
+
+       private static function interpolate( $message, array $context = array() 
) {
+               $replace = array();
+               foreach ( $context as $key => $val ) {
+                       $replace['{' . $key . '}'] = $val;
+               }
+               return strtr( $message, $replace );
+       }
+}
+
+/**
+ * Backwards compatible PSR-3 logger instance factory.
+ *
+ * PSR-3 debug logging was introduced to MediaWiki in 1.25. This class
+ * provides a backward compatible PSR-3 logging layer to make backporting
+ * critical updates from 1.25+ easier. It also serves to allow extensions that
+ * maintain backwards compatibility with the 1.23 LTS releases to migrate to
+ * the new logging system.
+ *
+ * @since 1.23.10
+ * @author Bryan Davis <[email protected]>
+ * @copyright © 2015 Bryan Davis and Wikimedia Foundation.
+ */
+class LoggerFactory {
+
+       /**
+        * Get a named logger instance.
+        *
+        * @param string $channel Logger channel (name)
+        * @return \Psr\Log\LoggerInterface
+        */
+       public static function getInstance( $channel ) {
+               return new Logger( $channel );
+       }
+
+       /**
+        * Construction of utility class is not allowed.
+        */
+       private function __construct() {
+               // no-op
+       }
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If385e722c62dc1f989af6fdee404535bad989acc
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: REL1_23
Gerrit-Owner: BryanDavis <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to