vendor/symfony/monolog-bridge/Logger.php line 23

  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.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 Symfony\Bridge\Monolog;
  11. use Monolog\Logger as BaseLogger;
  12. use Monolog\ResettableInterface;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
  15. use Symfony\Contracts\Service\ResetInterface;
  16. /**
  17.  * @author Fabien Potencier <fabien@symfony.com>
  18.  */
  19. class Logger extends BaseLogger implements DebugLoggerInterfaceResetInterface
  20. {
  21.     public function getLogs(Request $request null): array
  22.     {
  23.         if ($logger $this->getDebugLogger()) {
  24.             return $logger->getLogs($request);
  25.         }
  26.         return [];
  27.     }
  28.     public function countErrors(Request $request null): int
  29.     {
  30.         if ($logger $this->getDebugLogger()) {
  31.             return $logger->countErrors($request);
  32.         }
  33.         return 0;
  34.     }
  35.     /**
  36.      * @return void
  37.      */
  38.     public function clear()
  39.     {
  40.         if ($logger $this->getDebugLogger()) {
  41.             $logger->clear();
  42.         }
  43.     }
  44.     public function reset(): void
  45.     {
  46.         $this->clear();
  47.         if ($this instanceof ResettableInterface) {
  48.             parent::reset();
  49.         }
  50.     }
  51.     /**
  52.      * @return void
  53.      */
  54.     public function removeDebugLogger()
  55.     {
  56.         foreach ($this->processors as $k => $processor) {
  57.             if ($processor instanceof DebugLoggerInterface) {
  58.                 unset($this->processors[$k]);
  59.             }
  60.         }
  61.         foreach ($this->handlers as $k => $handler) {
  62.             if ($handler instanceof DebugLoggerInterface) {
  63.                 unset($this->handlers[$k]);
  64.             }
  65.         }
  66.     }
  67.     /**
  68.      * Returns a DebugLoggerInterface instance if one is registered with this logger.
  69.      */
  70.     private function getDebugLogger(): ?DebugLoggerInterface
  71.     {
  72.         foreach ($this->processors as $processor) {
  73.             if ($processor instanceof DebugLoggerInterface) {
  74.                 return $processor;
  75.             }
  76.         }
  77.         foreach ($this->handlers as $handler) {
  78.             if ($handler instanceof DebugLoggerInterface) {
  79.                 return $handler;
  80.             }
  81.         }
  82.         return null;
  83.     }
  84. }