jenkins-bot has submitted this change and it was merged.
Change subject: Add Monolog handlers and processors
......................................................................
Add Monolog handlers and processors
Things that log will now log to PSR\Logger\LoggerInterface instances
obtained from DonationLoggerFactory. The DonationLogProcessor will
prefix messages with relevant donation information.
Bug: T86266
Change-Id: Icf7e5a07c8c95b6dc517130070cd98c552e27ae4
---
M DonationInterface.php
M composer.json
M composer.lock
A gateway_common/DonationLogProcessor.php
A gateway_common/DonationLoggerFactory.php
M gateway_common/WmfFramework.php
A gateway_common/WmfFrameworkLogHandler.php
M gateway_common/gateway.adapter.php
M vendor
9 files changed, 225 insertions(+), 73 deletions(-)
Approvals:
Awight: Looks good to me, approved
jenkins-bot: Verified
diff --git a/DonationInterface.php b/DonationInterface.php
index 3b66bec..5486f53 100644
--- a/DonationInterface.php
+++ b/DonationInterface.php
@@ -101,16 +101,19 @@
$wgAutoloadClasses['CurrencyRates'] = $donationinterface_dir .
'gateway_common/CurrencyRates.php';
$wgAutoloadClasses['DonationData'] = $donationinterface_dir .
'gateway_common/DonationData.php';
+$wgAutoloadClasses['DonationLoggerFactory'] = $donationinterface_dir .
'gateway_common/DonationLoggerFactory.php';
+$wgAutoloadClasses['DonationLogProcessor'] = $donationinterface_dir .
'gateway_common/DonationLogProcessor.php';
$wgAutoloadClasses['EncodingMangler'] = $donationinterface_dir .
'gateway_common/EncodingMangler.php';
$wgAutoloadClasses['GatewayAdapter'] = $donationinterface_dir .
'gateway_common/gateway.adapter.php';
$wgAutoloadClasses['GatewayPage'] = $donationinterface_dir .
'gateway_common/GatewayPage.php';
$wgAutoloadClasses['GatewayType'] = $donationinterface_dir .
'gateway_common/gateway.adapter.php';
$wgAutoloadClasses['DataValidator'] = $donationinterface_dir .
'gateway_common/DataValidator.php';
+$wgAutoloadClasses['LogPrefixProvider'] = $donationinterface_dir .
'gateway_common/gateway.adapter.php';
$wgAutoloadClasses['NationalCurrencies'] = $donationinterface_dir .
'gateway_common/NationalCurrencies.php';
$wgAutoloadClasses['PaymentMethod'] = $donationinterface_dir .
'gateway_common/PaymentMethod.php';
$wgAutoloadClasses['PaymentResult'] = $donationinterface_dir .
'gateway_common/PaymentResult.php';
$wgAutoloadClasses['WmfFramework_Mediawiki'] = $donationinterface_dir .
'gateway_common/WmfFramework.mediawiki.php';
-require_once( 'gateway_common/WmfFramework.php' );
+$wgAutoloadClasses['WmfFrameworkLogHandler'] = $donationinterface_dir .
'gateway_common/WmfFrameworkLogHandler.php';
//load all possible form classes
$wgAutoloadClasses['Gateway_Form'] = $donationinterface_dir .
'gateway_forms/Form.php';
@@ -1060,3 +1063,15 @@
}
unset( $optionalParts );
+
+// Include composer's autoload if the vendor directory exists. If we have been
+// included via Composer, our dependencies should already be autoloaded at the
+// top level.
+// Note that in WMF's continuous integration, we can still only use stuff from
+// Composer if it is already in Mediawiki's vendor directory, such as monolog
+$vendorAutoload = __DIR__ . '/vendor/autoload.php';
+if ( file_exists( $vendorAutoload ) ) {
+ require_once ( $vendorAutoload );
+} else {
+ require_once ( 'gateway_common/WmfFramework.php' );
+}
diff --git a/composer.json b/composer.json
index 7fbf064..fe5c8c4 100644
--- a/composer.json
+++ b/composer.json
@@ -19,7 +19,7 @@
]
},
"require": {
- "fusesource/stomp-php": "2.*",
- "minfraud/http": "~1.60"
+ "psr/log": "1.0.0",
+ "monolog/monolog": "1.7.0"
}
}
diff --git a/composer.lock b/composer.lock
index e9876cc..5346e48 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,98 +4,112 @@
"Read more about it at
http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "hash": "db6cee8ab8789bf27fcaad9549734a6d",
+ "hash": "f66f26ac4c1ee0614474a94ce1de827c",
"packages": [
{
- "name": "fusesource/stomp-php",
- "version": "2.1.1",
+ "name": "monolog/monolog",
+ "version": "1.7.0",
"source": {
"type": "git",
- "url": "https://github.com/dejanb/stomp-php.git",
- "reference": "4ac51c0abee05078e198faf13f48c056a72f8f8c"
+ "url": "https://github.com/Seldaek/monolog.git",
+ "reference": "6225b22de9dcf36546be3a0b2fa8e3d986153f57"
},
"dist": {
"type": "zip",
- "url":
"https://api.github.com/repos/dejanb/stomp-php/zipball/4ac51c0abee05078e198faf13f48c056a72f8f8c",
- "reference": "4ac51c0abee05078e198faf13f48c056a72f8f8c",
+ "url":
"https://api.github.com/repos/Seldaek/monolog/zipball/6225b22de9dcf36546be3a0b2fa8e3d986153f57",
+ "reference": "6225b22de9dcf36546be3a0b2fa8e3d986153f57",
"shasum": ""
},
"require": {
- "php": ">=5.3.0"
+ "php": ">=5.3.0",
+ "psr/log": "~1.0"
+ },
+ "require-dev": {
+ "aws/aws-sdk-php": "~2.4.8",
+ "doctrine/couchdb": "dev-master",
+ "mlehner/gelf-php": "1.0.*",
+ "phpunit/phpunit": "~3.7.0",
+ "raven/raven": "0.5.*",
+ "ruflin/elastica": "0.90.*"
+ },
+ "suggest": {
+ "aws/aws-sdk-php": "Allow sending log messages to AWS services
like DynamoDB",
+ "doctrine/couchdb": "Allow sending log messages to a CouchDB
server",
+ "ext-amqp": "Allow sending log messages to an AMQP server
(1.0+ required)",
+ "ext-mongo": "Allow sending log messages to a MongoDB server",
+ "mlehner/gelf-php": "Allow sending log messages to a GrayLog2
server",
+ "raven/raven": "Allow sending log messages to a Sentry server",
+ "ruflin/elastica": "Allow sending log messages to an Elastic
Search server"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.7.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-0": {
+ "Monolog": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Jordi Boggiano",
+ "email": "[email protected]",
+ "homepage": "http://seld.be",
+ "role": "Developer"
+ }
+ ],
+ "description": "Sends your logs to files, sockets, inboxes,
databases and various web services",
+ "homepage": "http://github.com/Seldaek/monolog",
+ "keywords": [
+ "log",
+ "logging",
+ "psr-3"
+ ],
+ "time": "2013-11-14 19:48:31"
+ },
+ {
+ "name": "psr/log",
+ "version": "1.0.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/php-fig/log.git",
+ "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b"
+ },
+ "dist": {
+ "type": "zip",
+ "url":
"https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b",
+ "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b",
+ "shasum": ""
},
"type": "library",
"autoload": {
"psr-0": {
- "FuseSource": "src/"
+ "Psr\\Log\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
- "Apache-2.0"
+ "MIT"
],
"authors": [
{
- "name": "Dejan Bosnanac",
- "email": "[email protected]",
- "homepage": "http://www.nighttale.net"
- },
- {
- "name": "Sören Rohweder",
- "email": "[email protected]",
- "homepage": "http://www.monofone.de"
+ "name": "PHP-FIG",
+ "homepage": "http://www.php-fig.org/"
}
],
- "description": "stomp support for PHP",
- "homepage": "http://github.com/dejanb/stomp-php",
+ "description": "Common interface for logging libraries",
"keywords": [
- "activeMQ",
- "jms",
- "messaging",
- "stomp"
+ "log",
+ "psr",
+ "psr-3"
],
- "time": "2013-02-23 17:34:44"
- },
- {
- "name": "minfraud/http",
- "version": "v1.60",
- "source": {
- "type": "git",
- "url": "https://github.com/maxmind/ccfd-api-php.git",
- "reference": "553ceffe363185e20e17045d5058aba2154a6faf"
- },
- "dist": {
- "type": "zip",
- "url":
"https://api.github.com/repos/maxmind/ccfd-api-php/zipball/553ceffe363185e20e17045d5058aba2154a6faf",
- "reference": "553ceffe363185e20e17045d5058aba2154a6faf",
- "shasum": ""
- },
- "type": "library",
- "autoload": {
- "files": [
- "src/HTTPBase.php",
- "src/CreditCardFraudDetection.php",
- "src/TelephoneVerification.php"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "LGPL-2.1+"
- ],
- "authors": [
- {
- "name": "MaxMind, Inc.",
- "email": "[email protected]",
- "homepage": "http://www.maxmind.com/"
- }
- ],
- "description": "MaxMind minFraud HTTP API",
- "homepage": "https://github.com/maxmind/ccfd-api-php",
- "keywords": [
- "fraud",
- "maxmind",
- "minfraud"
- ],
- "time": "2014-07-23 16:34:20"
+ "time": "2012-12-21 11:40:51"
}
],
"packages-dev": [],
diff --git a/gateway_common/DonationLogProcessor.php
b/gateway_common/DonationLogProcessor.php
new file mode 100644
index 0000000..e282ee0
--- /dev/null
+++ b/gateway_common/DonationLogProcessor.php
@@ -0,0 +1,25 @@
+<?php
+
+/**
+ * Adds a prefix from a LogPrefixProvider to log messages
+ *
+ * @author Elliott Eggleston <[email protected]>
+ */
+class DonationLogProcessor {
+
+ protected $prefixer;
+
+ public function __construct( LogPrefixProvider $prefixer ) {
+ $this->prefixer = $prefixer;
+ }
+
+ public function __invoke( $record ) {
+ try {
+ $record['message'] =
$this->prefixer->getLogMessagePrefix() . $record['message'];
+ }
+ catch ( Exception $ex ) {
+ // logging shouldn't throw any exceptions
+ }
+ return $record;
+ }
+}
diff --git a/gateway_common/DonationLoggerFactory.php
b/gateway_common/DonationLoggerFactory.php
new file mode 100644
index 0000000..b472e68
--- /dev/null
+++ b/gateway_common/DonationLoggerFactory.php
@@ -0,0 +1,60 @@
+<?php
+use Monolog\Logger;
+use Monolog\Handler\SyslogHandler;
+
+/**
+ * Creates loggers for DonationInterface
+ *
+ * @author Elliott Eggleston <[email protected]>
+ */
+class DonationLoggerFactory {
+ /**
+ * For use by test harnesses to override the instance returned
+ * @var \Psr\Log\LoggerInterface
+ */
+ public static $overrideLogger = null;
+
+ /**
+ * @param GatewayAdapter $gateway Get settings from this instance
+ * @param string $suffix Append this string to the gateway identifier
+ * @param LogPrefixProvider $prefixer Optionally use this to override
+ * prefixing via the gateway.
+ * @return \Psr\Log\LoggerInterface
+ */
+ public static function getLogger( GatewayAdapter $gateway = null,
$suffix = '', LogPrefixProvider $prefixer = null ) {
+ if ( self::$overrideLogger !== null ) {
+ return self::$overrideLogger;
+ }
+ if ( $gateway === null ) {
+ $identifier = GatewayAdapter::getLogIdentifier();
+ $useSyslog = GatewayAdapter::getGlobal( 'UseSyslog' );
+ $debug = GatewayAdapter::getGlobal( 'LogDebug' );
+ } else {
+ $identifier = $gateway::getLogIdentifier();
+ $useSyslog = $gateway::getGlobal( 'UseSyslog' );
+ $debug = $gateway::getGlobal( 'LogDebug' );
+ }
+ $identifier = $identifier . $suffix;
+
+ $logger = new Logger( $identifier );
+ $logThreshold = $debug ? Logger::DEBUG : Logger::INFO;
+
+ if ( $useSyslog ) {
+ $handler = new SyslogHandler( $identifier, LOG_USER,
$logThreshold );
+ } else {
+ $handler = new WmfFrameworkLogHandler( $identifier,
$logThreshold );
+ }
+
+ if ( $prefixer === null ) {
+ $prefixer = $gateway;
+ }
+
+ // If either prefixer or gateway were non-null, add a processor
+ if ( $prefixer !== null ) {
+ $processor = new DonationLogProcessor( $prefixer );
+ $handler->pushProcessor( $processor );
+ }
+ $logger->pushHandler( $handler );
+ return $logger;
+ }
+}
diff --git a/gateway_common/WmfFramework.php b/gateway_common/WmfFramework.php
index e60b955..30cf896 100644
--- a/gateway_common/WmfFramework.php
+++ b/gateway_common/WmfFramework.php
@@ -1,8 +1,7 @@
<?php
if ( defined( 'MEDIAWIKI' ) ) {
- class_alias( 'WmfFramework_Mediawiki', 'WmfFramework' );
+ class_alias( 'WmfFramework_Mediawiki', 'WmfFramework', true );
} else {
- class_alias( 'WmfFramework_Drupal', 'WmfFramework' );
+ class_alias( 'WmfFramework_Drupal', 'WmfFramework', true );
}
-
diff --git a/gateway_common/WmfFrameworkLogHandler.php
b/gateway_common/WmfFrameworkLogHandler.php
new file mode 100644
index 0000000..0afb718
--- /dev/null
+++ b/gateway_common/WmfFrameworkLogHandler.php
@@ -0,0 +1,33 @@
+<?php
+use Monolog\Handler\AbstractProcessingHandler;
+use Monolog\Logger;
+
+/**
+ * Fallback log handler that dumps messages to WmfFramework's log backend when
+ * not using syslog
+ *
+ * @author Elliott Eggleston <[email protected]>
+ */
+class WmfFrameworkLogHandler extends AbstractProcessingHandler {
+
+ /**
+ * @var string
+ */
+ protected $identifier;
+
+ /**
+ * @param string $identifier String to write to wfDebugLog/watchdog
+ * @param integer $level The minimum logging level at which this handler
+ * will be triggered, as defined in
\Monolog\Logger
+ * @param Boolean $bubble Whether the messages that are handled can
bubble
+ * up the stack or not
+ */
+ public function __construct( $identifier, $level = Logger::DEBUG,
$bubble = true ) {
+ $this->identifier = $identifier;
+ parent::__construct( $level, $bubble );
+ }
+
+ protected function write( array $record ) {
+ WmfFramework::debugLog( $this->identifier, $record['message'] );
+ }
+}
diff --git a/gateway_common/gateway.adapter.php
b/gateway_common/gateway.adapter.php
index e01838a..cc7a2ee 100644
--- a/gateway_common/gateway.adapter.php
+++ b/gateway_common/gateway.adapter.php
@@ -166,6 +166,9 @@
function doPayment();
}
+interface LogPrefixProvider {
+ function getLogMessagePrefix();
+}
/**
* GatewayAdapter
*
@@ -1658,6 +1661,9 @@
return $c::IDENTIFIER;
}
+ static function getLogIdentifier() {
+ return self::getIdentifier() . '_gateway';
+ }
/**
* getStopwatch keeps track of how long things take, for logging,
* output, determining if we should loop on some method again...
whatever.
diff --git a/vendor b/vendor
index 4c18e54..abd7dd6 160000
--- a/vendor
+++ b/vendor
-Subproject commit 4c18e544fce5f14c09487f0cdd3ac39b40402ffc
+Subproject commit abd7dd6c9ac13a780945884e2bd1028ef54b7956
--
To view, visit https://gerrit.wikimedia.org/r/192385
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Icf7e5a07c8c95b6dc517130070cd98c552e27ae4
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: Katie Horn <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Ssmith <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits