mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 12:25:15 +08:00
add logger
This commit is contained in:
parent
3bd887aaa1
commit
8112a9bc83
9 changed files with 162 additions and 2 deletions
4
modules.local/woocommerce-logging/.gitignore
vendored
Normal file
4
modules.local/woocommerce-logging/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
/vendor/
|
||||
composer.lock
|
||||
phpunit.xml
|
||||
.phpunit.result.cache
|
13
modules.local/woocommerce-logging/composer.json
Normal file
13
modules.local/woocommerce-logging/composer.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "inpsyde/woocommerce-logging",
|
||||
"type": "inpsyde-module",
|
||||
"require": {
|
||||
"dhii/module-interface": "0.2.x-dev",
|
||||
"psr/log": "^1.1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Inpsyde\\Woocommerce\\Logging\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
13
modules.local/woocommerce-logging/extensions.php
Normal file
13
modules.local/woocommerce-logging/extensions.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* phpcs:disable Inpsyde.CodeQuality.ReturnTypeDeclaration
|
||||
* phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration
|
||||
*/
|
||||
|
||||
namespace Inpsyde\IZettle\Logging;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return [
|
||||
|
||||
];
|
9
modules.local/woocommerce-logging/module.php
Normal file
9
modules.local/woocommerce-logging/module.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\Woocommerce\Logging;
|
||||
|
||||
use Dhii\Modular\Module\ModuleInterface;
|
||||
|
||||
return function (): ModuleInterface {
|
||||
return new WoocommerceLoggingModule();
|
||||
};
|
23
modules.local/woocommerce-logging/services.php
Normal file
23
modules.local/woocommerce-logging/services.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* phpcs:disable Inpsyde.CodeQuality.ReturnTypeDeclaration
|
||||
* phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration
|
||||
*/
|
||||
|
||||
namespace Inpsyde\Woocommerce\Logging;
|
||||
|
||||
use Inpsyde\Woocommerce\Logging\Logger\NullLogger;
|
||||
use Inpsyde\Woocommerce\Logging\Logger\WooCommerceLogger;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return [
|
||||
'woocommerce.logger.woocommerce' => function (ContainerInterface $container) {
|
||||
if (!class_exists(\WC_Logger::class)) {
|
||||
return new NullLogger();
|
||||
}
|
||||
|
||||
return new WooCommerceLogger(
|
||||
wc_get_logger()
|
||||
);
|
||||
},
|
||||
];
|
22
modules.local/woocommerce-logging/src/Logger/NullLogger.php
Normal file
22
modules.local/woocommerce-logging/src/Logger/NullLogger.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType
|
||||
*/
|
||||
|
||||
namespace Inpsyde\Woocommerce\Logging\Logger;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\LoggerTrait;
|
||||
|
||||
class NullLogger implements LoggerInterface
|
||||
{
|
||||
|
||||
use LoggerTrait;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function log($level, $message, array $context = [])
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\Woocommerce\Logging\Logger;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\LoggerTrait;
|
||||
|
||||
/**
|
||||
* Class WooCommerceLogger
|
||||
* WooCommerce includes a logger interface, which is fully compatible to PSR-3,
|
||||
* but for some reason does not extend/implement it.
|
||||
*
|
||||
* This is a decorator that makes any WooCommerce Logger PSR-3-compatible
|
||||
*
|
||||
* @package Inpsyde\IZettle\Logging\Logger
|
||||
*/
|
||||
class WooCommerceLogger implements LoggerInterface
|
||||
{
|
||||
|
||||
use LoggerTrait;
|
||||
|
||||
/**
|
||||
* @var \WC_Logger_Interface
|
||||
*/
|
||||
private $wcLogger;
|
||||
|
||||
public function __construct(\WC_Logger_Interface $wcLogger)
|
||||
{
|
||||
$this->wcLogger = $wcLogger;
|
||||
}
|
||||
|
||||
/**
|
||||
* phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function log($level, $message, array $context = [])
|
||||
{
|
||||
if (!isset($context['source'])) {
|
||||
$context['source'] = 'izettle-woocommerce';
|
||||
}
|
||||
$this->wcLogger->log($level, $message, $context);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\Woocommerce\Logging;
|
||||
|
||||
use Dhii\Container\ServiceProvider;
|
||||
use Dhii\Modular\Module\ModuleInterface;
|
||||
use Interop\Container\ServiceProviderInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class WoocommerceLoggingModule implements ModuleInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setup(): ServiceProviderInterface
|
||||
{
|
||||
return new ServiceProvider(
|
||||
require __DIR__.'/../services.php',
|
||||
require __DIR__.'/../extensions.php'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function run(ContainerInterface $container)
|
||||
{
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue