Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gateway/Request/AdditionalDataLevel23DataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function build(array $buildSubject): array

// `totalTaxAmount` field is required and L2/L3 data can not be generated without this field.
if (empty($order->getTaxAmount()) || $order->getTaxAmount() < 0 || $order->getTaxAmount() === 0) {
$this->adyenLogger->warning(__('L2/L3 data can not be generated if tax amount is zero.'));
$this->adyenLogger->addAdyenWarning(__('L2/L3 data can not be generated if tax amount is zero.'));
return $request;
}

Expand Down
2 changes: 1 addition & 1 deletion Gateway/Response/PaymentCaptureDetailsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function handle(array $handlingSubject, array $response)
public function handlePartialOrMultipleCaptureRequests(Order\Payment $payment, $responseContainer)
{
$lastTransId = null;
$this->adyenLogger->info(sprintf(
$this->adyenLogger->addAdyenInfoLog(sprintf(
'Handling partial OR multiple capture response in details handler for order %s',
$payment->getOrder()->getIncrementId()
));
Expand Down
2 changes: 1 addition & 1 deletion Gateway/Response/PaymentCommentHistoryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function handle(array $handlingSubject, array $response)
*/
private function handlePartialOrMultipleCaptureRequests($payment, array $responseContainer)
{
$this->adyenLogger->info(sprintf(
$this->adyenLogger->addAdyenInfoLog(sprintf(
'Handling partial OR multiple capture response in comment history handler for order %s',
$payment->getOrder()->getIncrementId()
));
Expand Down
2 changes: 1 addition & 1 deletion Helper/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function getStreetAndHouseNumberFromAddress(
} elseif ($address instanceof OrderAddressInterface) {
$addressArray = $address->getStreet();
} else {
$this->logger->warning(sprintf(
$this->logger->addAdyenWarning(sprintf(
'Unknown address type %s passed to the getStreetAndHouseNumberFromAddress function',
get_class($address)
));
Expand Down
4 changes: 2 additions & 2 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ public function logRequest(array $request, $apiVersion, $endpoint)
$context['body'] = $this->filterReferences($request);
}

$this->adyenLogger->info('Request to Adyen API ' . $endpoint, $context);
$this->adyenLogger->addAdyenInfoLog('Request to Adyen API ' . $endpoint, $context);
}

public function logResponse(array $response)
Expand All @@ -1368,7 +1368,7 @@ public function logResponse(array $response)
$context['body'] = $this->filterReferences($response);
}

$this->adyenLogger->info('Response from Adyen API', $context);
$this->adyenLogger->addAdyenInfoLog('Response from Adyen API', $context);
}

public function logAdyenException(AdyenException $e)
Expand Down
2 changes: 1 addition & 1 deletion Helper/ManagementHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public function webhookTest(
$response = null;
try {
$response = $service->testWebhook($merchantId, $webhookId, $testWebhookRequest);
$this->adyenLogger->info(sprintf('response from webhook test %s', $response));
$this->adyenLogger->addAdyenInfoLog(sprintf('response from webhook test %s', $response));
} catch (AdyenException $exception) {
$this->adyenLogger->error($exception->getMessage());
}
Expand Down
150 changes: 102 additions & 48 deletions Logger/AdyenLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* Copyright (c) 2025 Adyen N.V. (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
Expand All @@ -12,55 +12,37 @@
namespace Adyen\Payment\Logger;

use Adyen\Payment\Helper\Config;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Phrase;
use Magento\Sales\Model\Order as MagentoOrder;
use Magento\Store\Model\StoreManagerInterface;
use Monolog\Level;
use Monolog\Logger;
use Monolog\LoggerFactory;

class AdyenLogger extends Logger
class AdyenLogger
{
/**
* Detailed debug information
*/
const ADYEN_DEBUG = 101;
const ADYEN_NOTIFICATION = 201;
const ADYEN_RESULT = 202;
/**
* Logging levels from syslog protocol defined in RFC 5424
* Overrule the default to add Adyen specific loggers to log into seperate files
*
* @var array $levels Logging levels
*/
protected static $levels = [
100 => 'DEBUG',
101 => 'ADYEN_DEBUG',
200 => 'INFO',
201 => 'ADYEN_NOTIFICATION',
202 => 'ADYEN_RESULT',
250 => 'NOTICE',
300 => 'WARNING',
400 => 'ERROR',
500 => 'CRITICAL',
550 => 'ALERT',
600 => 'EMERGENCY',
];

/**
* @var Config
*/
private $config;
const ADYEN_INFO = 203;
const ADYEN_WARNING = 301;
const ADYEN_ERROR = 401;

/**
* @var StoreManagerInterface
* @param Config $config
* @param StoreManagerInterface $storeManager
* @param LoggerFactory $loggerFactory
* @param array $handlers
* @param array $processors
*/
private $storeManager;

public function __construct(Config $config, StoreManagerInterface $storeManager, $name, array $handlers = array(), array $processors = array())
{
parent::__construct($name, $handlers, $processors);
$this->config = $config;
$this->storeManager = $storeManager;
}
public function __construct(
private readonly Config $config,
private readonly StoreManagerInterface $storeManager,
private readonly LoggerFactory $loggerFactory,
private array $handlers = [],
private array $processors = []
) { }

/**
* Adds a webhook notification log record.
Expand All @@ -71,27 +53,49 @@ public function __construct(Config $config, StoreManagerInterface $storeManager,
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function addAdyenNotification($message, array $context = [])
public function addAdyenNotification(string $message, array $context = []): bool
{
return $this->addRecord(static::ADYEN_NOTIFICATION, $message, $context);
$logger = $this->generateLogger(self::ADYEN_NOTIFICATION);
return $logger->addRecord(Level::Info, $message, $context);
}

public function addAdyenDebug($message, array $context = [])
/**
* @param string $message
* @param array $context
* @return bool
* @throws NoSuchEntityException
*/
public function addAdyenDebug(string $message, array $context = []): bool
{
$storeId = $this->storeManager->getStore()->getId();
if ($this->config->debugLogsEnabled($storeId)) {
return $this->addRecord(static::ADYEN_DEBUG, $message, $context);
$logger = $this->generateLogger(self::ADYEN_DEBUG);
return $logger->addRecord(Level::Debug, $message, $context);
} else {
return false;
}
}

public function addAdyenWarning($message, array $context = []): bool
/**
* @param string $message
* @param array $context
* @return bool
*/
public function addAdyenWarning(string $message, array $context = []): bool
{
return $this->addRecord(static::WARNING, $message, $context);
$logger = $this->generateLogger(self::ADYEN_WARNING);
return $logger->addRecord(Level::Warning, $message, $context);
}

public function addAdyenResult($message, array $context = [])
/**
* @param string $message
* @param array $context
* @return bool
*/
public function addAdyenResult(string $message, array $context = []): bool
{
return $this->addRecord(static::ADYEN_RESULT, $message, $context);
$logger = $this->generateLogger(self::ADYEN_RESULT);
return $logger->addRecord(Level::Info, $message, $context);
}

/**
Expand All @@ -103,9 +107,21 @@ public function addAdyenResult($message, array $context = [])
* @param array $context The log context
* @return Boolean Whether the record has been processed
*/
public function addAdyenInfoLog($message, array $context = [])
public function addAdyenInfoLog(string $message, array $context = []): bool
{
$logger = $this->generateLogger(self::ADYEN_INFO);
return $logger->addRecord(Level::Info, $message, $context);
}

/**
* @param string $message
* @param array $context
* @return bool
*/
public function error(string $message, array $context = []): bool
{
return $this->addRecord(static::INFO, $message, $context);
$logger = $this->generateLogger(self::ADYEN_ERROR);
return $logger->addRecord(Level::Error, $message, $context);
}

public function getOrderContext(MagentoOrder $order): array
Expand Down Expand Up @@ -134,4 +150,42 @@ public function getInvoiceContext(MagentoOrder\Invoice $invoice): array
'invoiceCanRefund' => $invoice->canRefund()
];
}

/**
* @param int $handler
* @return Logger
*/
private function generateLogger(int $handler): Logger
{
/** @var Logger $logger */
$logger = $this->loggerFactory->create(['name' => 'Adyen Logger']);

foreach ($this->processors as $processor) {
$logger->pushProcessor($processor);
}

switch ($handler) {
case self::ADYEN_NOTIFICATION:
$logger->pushHandler($this->handlers['adyenNotification']);
break;
case self::ADYEN_WARNING:
$logger->pushHandler($this->handlers['adyenWarning']);
break;
case self::ADYEN_RESULT:
$logger->pushHandler($this->handlers['adyenResult']);
break;
case self::ADYEN_INFO:
$logger->pushHandler($this->handlers['adyenInfo']);
break;
case self::ADYEN_ERROR:
$logger->pushHandler($this->handlers['adyenError']);
break;
case self::ADYEN_DEBUG:
default:
$logger->pushHandler($this->handlers['adyenDebug']);
break;
}

return $logger;
}
}
50 changes: 0 additions & 50 deletions Logger/Handler/AdyenBase.php

This file was deleted.

20 changes: 6 additions & 14 deletions Logger/Handler/AdyenDebug.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,20 @@
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* Copyright (c) 2025 Adyen N.V. (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/

namespace Adyen\Payment\Logger\Handler;

use Adyen\Payment\Logger\AdyenLogger;
use Monolog\Logger;
use Magento\Framework\Logger\Handler\Base;
use Monolog\Level;

class AdyenDebug extends AdyenBase
class AdyenDebug extends Base
{
/**
* @var string
*/
protected $fileName = '/var/log/adyen/debug.log';

/**
* @var int
*/
protected $loggerType = AdyenLogger::ADYEN_DEBUG;

protected $level = AdyenLogger::ADYEN_DEBUG;
protected $loggerType = Level::Debug;
protected Level $level = Level::Debug;
}
23 changes: 6 additions & 17 deletions Logger/Handler/AdyenError.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,20 @@
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* Copyright (c) 2025 Adyen N.V. (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/

namespace Adyen\Payment\Logger\Handler;

use Adyen\Payment\Logger\AdyenLogger;
use Monolog\Logger;
use Magento\Framework\Logger\Handler\Base;
use Monolog\Level;

class AdyenError extends AdyenBase
class AdyenError extends Base
{
/**
* @var string
*/
protected $fileName = '/var/log/adyen/error.log';

/**
* @var int
*/
protected $loggerType = AdyenLogger::ERROR;

/**
* @var
*/
protected $level = AdyenLogger::ERROR;
protected $loggerType = Level::Error;
protected Level $level = Level::Error;
}
Loading
Loading