Skip to content

Commit

Permalink
Restore http logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt75 committed Feb 28, 2024
1 parent fd96d88 commit d200906
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions src/Http/CheckoutHttpClientConfigurationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@

namespace PrestaShop\Module\PrestashopCheckout\Http;

use GuzzleHttp\Event\Emitter;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Subscriber\Log\Formatter;
use GuzzleHttp\Subscriber\Log\LogSubscriber;
use GuzzleLogMiddleware\LogMiddleware;
use PrestaShop\Module\PrestashopCheckout\Context\PrestaShopContext;
use PrestaShop\Module\PrestashopCheckout\Environment\PaymentEnv;
use PrestaShop\Module\PrestashopCheckout\Logger\LoggerConfiguration;
use PrestaShop\Module\PrestashopCheckout\Repository\PsAccountRepository;
use PrestaShop\Module\PrestashopCheckout\Routing\Router;
use PrestaShop\Module\PrestashopCheckout\ShopContext;
use Ps_checkout;
use Psr\Log\LoggerInterface;

class CheckoutHttpClientConfigurationBuilder implements HttpClientConfigurationBuilderInterface
{
Expand Down Expand Up @@ -56,26 +63,40 @@ class CheckoutHttpClientConfigurationBuilder implements HttpClientConfigurationB
*/
private $prestaShopContext;

/**
* @var LoggerConfiguration
*/
private $loggerConfiguration;

/**
* @var LoggerInterface
*/
private $logger;

public function __construct(
PaymentEnv $paymentEnv,
Router $router,
ShopContext $shopContext,
PsAccountRepository $psAccountRepository,
PrestaShopContext $prestaShopContext
PrestaShopContext $prestaShopContext,
LoggerConfiguration $loggerConfiguration,
LoggerInterface $logger
) {
$this->paymentEnv = $paymentEnv;
$this->router = $router;
$this->shopContext = $shopContext;
$this->psAccountRepository = $psAccountRepository;
$this->prestaShopContext = $prestaShopContext;
$this->loggerConfiguration = $loggerConfiguration;
$this->logger = $logger;
}

/**
* @return array
*/
public function build()
{
return [
$configuration = [
'base_url' => $this->paymentEnv->getPaymentApiUrl(),
'verify' => $this->getVerify(),
'timeout' => static::TIMEOUT,
Expand All @@ -90,6 +111,33 @@ public function build()
'Prestashop-Version' => _PS_VERSION_, // prestashop version
],
];

if (
$this->loggerConfiguration->isHttpEnabled()
&& defined('\GuzzleHttp\ClientInterface::MAJOR_VERSION')
&& class_exists(HandlerStack::class)
&& class_exists(LogMiddleware::class)
) {
$handlerStack = HandlerStack::create();
$handlerStack->push(new LogMiddleware($this->logger));
$configuration['handler'] = $handlerStack;
} elseif (
$this->loggerConfiguration->isHttpEnabled()
&& defined('\GuzzleHttp\ClientInterface::VERSION')
&& class_exists(Emitter::class)
&& class_exists(LogSubscriber::class)
&& class_exists(Formatter::class)
) {
$emitter = new Emitter();
$emitter->attach(new LogSubscriber(
$this->logger,
Formatter::DEBUG
));

$configuration['emitter'] = $emitter;
}

return $configuration;
}

/**
Expand Down

0 comments on commit d200906

Please sign in to comment.