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