make logging optional

This commit is contained in:
David Remer 2020-07-10 15:45:49 +03:00
parent 6c97b6332b
commit b032a8ea14
2 changed files with 31 additions and 0 deletions

View file

@ -4,7 +4,10 @@ declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\WcGateway;
use Inpsyde\Woocommerce\Logging\Logger\NullLogger;
use Inpsyde\Woocommerce\Logging\Logger\WooCommerceLogger;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
return [
@ -29,4 +32,16 @@ return [
$settings = $container->get('wcgateway.settings');
return $settings->has('client_secret') ? (string) $settings->get('client_secret') : '';
},
'woocommerce.logger.woocommerce' => function (ContainerInterface $container): LoggerInterface {
$settings = $container->get('wcgateway.settings');
if (! $settings->has('logging_enabled') || ! $settings->get('logging_enabled')) {
return new NullLogger();
}
$source = $container->get('woocommerce.logger.source');
return new WooCommerceLogger(
wc_get_logger(),
$source
);
},
];

View file

@ -17,6 +17,9 @@ use Inpsyde\PayPalCommerce\WcGateway\Processor\OrderProcessor;
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsListener;
use Inpsyde\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
use Inpsyde\Woocommerce\Logging\Logger\NullLogger;
use Inpsyde\Woocommerce\Logging\Logger\WooCommerceLogger;
use Psr\Log\LoggerInterface;
use WpOop\TransientCache\CachePoolFactory;
return [
@ -411,6 +414,19 @@ return [
State::STATE_ONBOARDED,
],
],
'logging_enabled' => [
'title' => __('Logging', 'woocommerce-paypal-commerce-gateway'),
'type' => 'checkbox',
'desc_tip' => true,
'label' => __('Enable logging', 'woocommerce-paypal-commerce-gateway'),
'description' => __('Enable logging of unexpected behavior. This can also log private data and should only be enabled in a development or stage environment.', 'woocommerce-paypal-commerce-gateway'),
'default' => false,
'screens' => [
State::STATE_START,
State::STATE_PROGRESSIVE,
State::STATE_ONBOARDED,
],
],
];
},
];