vendor/friendsofsymfony/http-cache/src/EventListener/LogListener.php line 43

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the FOSHttpCache package.
  4. *
  5. * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace FOS\HttpCache\EventListener;
  11. use FOS\HttpCache\Event;
  12. use FOS\HttpCache\Events;
  13. use Psr\Log\LoggerInterface;
  14. use Psr\Log\LogLevel;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. /**
  17. * Log when the caching proxy client can't send requests to the caching server.
  18. */
  19. class LogListener implements EventSubscriberInterface
  20. {
  21. /**
  22. * @var LoggerInterface
  23. */
  24. private $logger;
  25. public function __construct(LoggerInterface $logger)
  26. {
  27. $this->logger = $logger;
  28. }
  29. public static function getSubscribedEvents(): array
  30. {
  31. return [
  32. Events::PROXY_UNREACHABLE_ERROR => 'onProxyUnreachableError',
  33. Events::PROXY_RESPONSE_ERROR => 'onProxyResponseError',
  34. ];
  35. }
  36. public function onProxyUnreachableError(Event $event)
  37. {
  38. $this->log(LogLevel::CRITICAL, $event->getException());
  39. }
  40. public function onProxyResponseError(Event $event)
  41. {
  42. $this->log(LogLevel::CRITICAL, $event->getException());
  43. }
  44. private function log($level, \Exception $exception)
  45. {
  46. $context = [
  47. 'exception' => $exception,
  48. ];
  49. $this->logger->log($level, $exception->getMessage(), $context);
  50. }
  51. }