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

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.     /**
  30.      * {@inheritdoc}
  31.      */
  32.     public static function getSubscribedEvents(): array
  33.     {
  34.         return [
  35.             Events::PROXY_UNREACHABLE_ERROR => 'onProxyUnreachableError',
  36.             Events::PROXY_RESPONSE_ERROR => 'onProxyResponseError',
  37.         ];
  38.     }
  39.     public function onProxyUnreachableError(Event $event)
  40.     {
  41.         $this->log(LogLevel::CRITICAL$event->getException());
  42.     }
  43.     public function onProxyResponseError(Event $event)
  44.     {
  45.         $this->log(LogLevel::CRITICAL$event->getException());
  46.     }
  47.     private function log($level\Exception $exception)
  48.     {
  49.         $context = [
  50.             'exception' => $exception,
  51.         ];
  52.         $this->logger->log($level$exception->getMessage(), $context);
  53.     }
  54. }