86 lines
2.2 KiB
PHP
86 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace External\FlexiBeeBundle\Util;
|
|
|
|
use Doctrine\DBAL\Exception\DeadlockException;
|
|
use Doctrine\DBAL\Exception\LockWaitTimeoutException;
|
|
use External\FlexiBeeBundle\Exception\FlexiBeeException;
|
|
use KupShop\AdminBundle\Util\ActivityLog;
|
|
use KupShop\KupShopBundle\Util\Logging\SentryLogger;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class FlexiBeeLogger
|
|
{
|
|
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;
|
|
}
|
|
|
|
/**
|
|
* Zaloguje exceptionu do ActivityLogu, pripadne do Sentry.
|
|
*/
|
|
public function exception(\Throwable $e, ?string $message = null, array $data = []): void
|
|
{
|
|
if (isLocalDevelopment()) {
|
|
throw $e;
|
|
}
|
|
|
|
if (!($e instanceof FlexiBeeException)) {
|
|
$this->sentryLogger->captureException($e);
|
|
}
|
|
|
|
if ($message === null) {
|
|
$message = $e->getMessage();
|
|
}
|
|
|
|
$data = array_merge(
|
|
[
|
|
'exception_message' => $e->getMessage(),
|
|
],
|
|
$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,
|
|
array_unique($data)
|
|
);
|
|
}
|
|
|
|
public function activity(string $message, array $data = [], string $severity = ActivityLog::SEVERITY_NOTICE): void
|
|
{
|
|
$this->activityLog->addActivityLog(
|
|
$severity,
|
|
ActivityLog::TYPE_SYNC,
|
|
'[FlexiBee] '.$message,
|
|
$data
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Zaloguje data do kibany.
|
|
*/
|
|
public function data(string $message, array $data): void
|
|
{
|
|
if (isLocalDevelopment()) {
|
|
return;
|
|
}
|
|
|
|
$this->logger->notice($message, $data);
|
|
}
|
|
}
|