72 lines
2.2 KiB
PHP
72 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace External\PompoBundle\Util;
|
|
|
|
use Doctrine\DBAL\Exception\DeadlockException;
|
|
use Doctrine\DBAL\Exception\LockWaitTimeoutException;
|
|
use External\PompoBundle\DataGo\Exception\DataGoException;
|
|
use External\PompoBundle\Exception\PompoException;
|
|
use KupShop\AdminBundle\Util\ActivityLog;
|
|
use KupShop\KupShopBundle\Util\Logging\SentryLogger;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class PompoLogger
|
|
{
|
|
private ActivityLog $activityLog;
|
|
private SentryLogger $sentryLogger;
|
|
private LoggerInterface $logger;
|
|
|
|
public function __construct(ActivityLog $activityLog, SentryLogger $sentryLogger, LoggerInterface $logger)
|
|
{
|
|
$this->activityLog = $activityLog;
|
|
$this->sentryLogger = $sentryLogger;
|
|
$this->logger = $logger;
|
|
}
|
|
|
|
public function logException(\Throwable $e, string $message, array $data = []): void
|
|
{
|
|
if (isDevelopment()) {
|
|
throw $e;
|
|
}
|
|
|
|
// TODO: mozna casem odebrat, at logujeme jen do activity logu
|
|
if (!($e instanceof PompoException) && !($e instanceof \SoapFault)) {
|
|
$this->sentryLogger->captureException($e);
|
|
}
|
|
|
|
// PompoException na sobe muze mit i nejaky data na vic
|
|
if ($e instanceof PompoException) {
|
|
$prefix = $e instanceof DataGoException ? '[DataGo]' : '[DRS]';
|
|
$exceptionData = array_merge(['exceptionMessage' => $prefix.' '.$e->getMessage()], $e->getData());
|
|
if ($e->getDetailedMessage()) {
|
|
$exceptionData = array_merge(['detailedMessage' => $e->getDetailedMessage()], $exceptionData);
|
|
}
|
|
|
|
$data = array_merge($exceptionData, $data);
|
|
}
|
|
|
|
// Lock wait timeout a deadlock nechci logovat do ActivityLogu
|
|
if ($e instanceof LockWaitTimeoutException || $e instanceof DeadlockException) {
|
|
return;
|
|
}
|
|
|
|
$this->activityLog->addActivityLog(
|
|
ActivityLog::SEVERITY_ERROR,
|
|
ActivityLog::TYPE_SYNC,
|
|
$message,
|
|
$data
|
|
);
|
|
}
|
|
|
|
public function log(string $message, array $data): void
|
|
{
|
|
if (isDevelopment()) {
|
|
return;
|
|
}
|
|
|
|
$this->logger->notice($message, $data);
|
|
}
|
|
}
|