feat(logging): Implement database logging with app_log table

- Created migration to set up app_log table for storing application logs.
- Added AppLog entity and repository for ORM handling of logs.
- Developed DbLogger service to persist logs of level WARNING and above to the database while maintaining existing logging behavior.
- Implemented tests for admin log retrieval and DbLogger functionality to ensure proper logging behavior.
- Enhanced logging context sanitization for better error tracking.
This commit is contained in:
hamed
2026-06-29 20:01:03 +03:30
parent 830f7e8d0c
commit 803196108c
38 changed files with 3284 additions and 618 deletions
+4
View File
@@ -3,6 +3,7 @@
namespace App\Payment\Gateway;
use App\Config\Repository\SiteConfigRepository;
use Psr\Log\LoggerInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class MellatGateway implements PaymentGatewayInterface
@@ -12,6 +13,7 @@ class MellatGateway implements PaymentGatewayInterface
public function __construct(
private readonly HttpClientInterface $httpClient,
private readonly SiteConfigRepository $configRepo,
private readonly LoggerInterface $logger,
private readonly string $terminalId = '',
private readonly string $username = '',
private readonly string $password = '',
@@ -46,6 +48,7 @@ class MellatGateway implements PaymentGatewayInterface
return new PaymentInitResult(true, redirectUrl: $redirectUrl, token: $refId);
} catch (\Throwable $e) {
$this->logger->error(sprintf('Payment initiate failed (mellat): %s @ %s:%d', $e->getMessage(), $e->getFile(), $e->getLine()), ['exception' => $e, 'orderId' => $orderId, 'amount' => $amountRials]);
return new PaymentInitResult(false, errorMessage: $e->getMessage());
}
}
@@ -79,6 +82,7 @@ class MellatGateway implements PaymentGatewayInterface
return new PaymentVerifyResult(true, referenceId: $refId);
} catch (\Throwable $e) {
$this->logger->error(sprintf('Payment verify failed (mellat): %s @ %s:%d', $e->getMessage(), $e->getFile(), $e->getLine()), ['exception' => $e, 'refId' => $refId]);
return new PaymentVerifyResult(false, errorMessage: $e->getMessage());
}
}
+4
View File
@@ -3,6 +3,7 @@
namespace App\Payment\Gateway;
use App\Config\Repository\SiteConfigRepository;
use Psr\Log\LoggerInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class SepGateway implements PaymentGatewayInterface
@@ -13,6 +14,7 @@ class SepGateway implements PaymentGatewayInterface
public function __construct(
private readonly HttpClientInterface $httpClient,
private readonly SiteConfigRepository $configRepo,
private readonly LoggerInterface $logger,
private readonly string $terminalId = '',
) {}
@@ -47,6 +49,7 @@ class SepGateway implements PaymentGatewayInterface
return new PaymentInitResult(true, redirectUrl: $redirectUrl, token: $token);
} catch (\Throwable $e) {
$this->logger->error(sprintf('Payment initiate failed (sep): %s @ %s:%d', $e->getMessage(), $e->getFile(), $e->getLine()), ['exception' => $e, 'orderId' => $orderId, 'amount' => $amountRials]);
return new PaymentInitResult(false, errorMessage: $e->getMessage());
}
}
@@ -84,6 +87,7 @@ class SepGateway implements PaymentGatewayInterface
amountRials: (int) $data['TransactionDetail']['AffectiveAmount']
);
} catch (\Throwable $e) {
$this->logger->error(sprintf('Payment verify failed (sep): %s @ %s:%d', $e->getMessage(), $e->getFile(), $e->getLine()), ['exception' => $e, 'refNum' => $refNum]);
return new PaymentVerifyResult(false, errorMessage: $e->getMessage());
}
}