Commit 337b1736 by Lech Sawon

log error

parent ece7f1a1
...@@ -4,6 +4,7 @@ declare(strict_types=1); ...@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Subscriber; namespace App\Subscriber;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
...@@ -14,10 +15,12 @@ use Symfony\Component\HttpKernel\KernelEvents; ...@@ -14,10 +15,12 @@ use Symfony\Component\HttpKernel\KernelEvents;
final class ApiExceptionSubscriber implements EventSubscriberInterface final class ApiExceptionSubscriber implements EventSubscriberInterface
{ {
private RequestStack $requestStack; private RequestStack $requestStack;
private LoggerInterface $logger;
public function __construct(RequestStack $requestStack) public function __construct(RequestStack $requestStack, LoggerInterface $logger)
{ {
$this->requestStack = $requestStack; $this->requestStack = $requestStack;
$this->logger = $logger;
} }
...@@ -25,13 +28,19 @@ final class ApiExceptionSubscriber implements EventSubscriberInterface ...@@ -25,13 +28,19 @@ final class ApiExceptionSubscriber implements EventSubscriberInterface
{ {
return [ return [
KernelEvents::EXCEPTION => [ KernelEvents::EXCEPTION => [
['logException', 100],
['processException', 10], ['processException', 10],
['logException', 0],
] ]
]; ];
} }
public function logException(ExceptionEvent $event)
{
$exception = $event->getThrowable();
$this->logger->alert($exception->getMessage());
}
public function processException(ExceptionEvent $event) public function processException(ExceptionEvent $event)
{ {
$request = $this->requestStack->getCurrentRequest(); $request = $this->requestStack->getCurrentRequest();
...@@ -67,9 +76,4 @@ final class ApiExceptionSubscriber implements EventSubscriberInterface ...@@ -67,9 +76,4 @@ final class ApiExceptionSubscriber implements EventSubscriberInterface
} }
} }
public function logException(ExceptionEvent $event) {
//@TODO
// np używając logger Interface
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment