src/EventListener/LogPublisherSubscriber.php line 26
<?phpnamespace App\EventListener;use App\Event\HttpLogEvent;use App\Service\LogPublisher\Domain\HttpLog;use App\Service\LogPublisher\LogPublisherServiceInterface;use Psr\Log\LoggerInterface;use Symfony\Component\EventDispatcher\EventSubscriberInterface;class LogPublisherSubscriber implements EventSubscriberInterface{public function __construct(private LoggerInterface $logger,private LogPublisherServiceInterface $logPublisherService,private bool $httpLoggingEnabled,) {}public static function getSubscribedEvents(): array{return [HttpLogEvent::class => 'logHttpEvent',];}public function logHttpEvent(HttpLogEvent $event): void{try {// must be non-fatal$httpLog = $this->buildHttpLog($event);// $this->logger->notice(json_encode($httpLog));// Local debug: Use one of the following two options// $log = json_encode($httpLog);// $log = $httpLog->__toString();// file_put_contents('/opt/gateway-2/gateway-2/output'.time().'.txt', $log."\n\n", FILE_APPEND | LOCK_EX);// TODO: Sanitise sensitive data in http request/response// TODO: Restrict to trigger only in booking/cancellation flowif ($this->httpLoggingEnabled) {$this->logPublisherService->logHttp($httpLog);}} catch (\Throwable $e) {$this->logger->error('Error when trying to publish logs: '.$e->getMessage());}}private function buildHttpLog(HttpLogEvent $event): HttpLog{$request = $event->getRequest();$response = $event->getResponse();$uri = $request->getUri();$statusCode = $response->getStatusCode();$dateTime = date('c', time());return new HttpLog(url: $uri,request: $request,response: $response,status: $statusCode,dateTime: $dateTime,);}}