vendor/symfony/monolog-bridge/Processor/DebugProcessor.php line 20

Open in your IDE?
  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\Processor;
  11. use Monolog\Logger;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\RequestStack;
  14. use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
  15. use Symfony\Contracts\Service\ResetInterface;
  16. class DebugProcessor implements DebugLoggerInterfaceResetInterface
  17. {
  18.     private $records = [];
  19.     private $errorCount = [];
  20.     private $requestStack;
  21.     public function __construct(RequestStack $requestStack null)
  22.     {
  23.         $this->requestStack $requestStack;
  24.     }
  25.     public function __invoke(array $record)
  26.     {
  27.         $hash $this->requestStack && ($request $this->requestStack->getCurrentRequest()) ? spl_object_hash($request) : '';
  28.         $this->records[$hash][] = [
  29.             'timestamp' => $record['datetime'] instanceof \DateTimeInterface $record['datetime']->getTimestamp() : strtotime($record['datetime']),
  30.             'message' => $record['message'],
  31.             'priority' => $record['level'],
  32.             'priorityName' => $record['level_name'],
  33.             'context' => $record['context'],
  34.             'channel' => $record['channel'] ?? '',
  35.         ];
  36.         if (!isset($this->errorCount[$hash])) {
  37.             $this->errorCount[$hash] = 0;
  38.         }
  39.         switch ($record['level']) {
  40.             case Logger::ERROR:
  41.             case Logger::CRITICAL:
  42.             case Logger::ALERT:
  43.             case Logger::EMERGENCY:
  44.                 ++$this->errorCount[$hash];
  45.         }
  46.         return $record;
  47.     }
  48.     /**
  49.      * {@inheritdoc}
  50.      *
  51.      * @param Request|null $request
  52.      */
  53.     public function getLogs(/* Request $request = null */)
  54.     {
  55.         if (\func_num_args() < && __CLASS__ !== static::class && __CLASS__ !== (new \ReflectionMethod($this__FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface && !$this instanceof \Mockery\MockInterface) {
  56.             @trigger_error(sprintf('The "%s()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.'__METHOD__), \E_USER_DEPRECATED);
  57.         }
  58.         if (<= \func_num_args() && null !== $request func_get_arg(0)) {
  59.             return $this->records[spl_object_hash($request)] ?? [];
  60.         }
  61.         if (=== \count($this->records)) {
  62.             return [];
  63.         }
  64.         return array_merge(...array_values($this->records));
  65.     }
  66.     /**
  67.      * {@inheritdoc}
  68.      *
  69.      * @param Request|null $request
  70.      */
  71.     public function countErrors(/* Request $request = null */)
  72.     {
  73.         if (\func_num_args() < && __CLASS__ !== static::class && __CLASS__ !== (new \ReflectionMethod($this__FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface && !$this instanceof \Mockery\MockInterface) {
  74.             @trigger_error(sprintf('The "%s()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.'__METHOD__), \E_USER_DEPRECATED);
  75.         }
  76.         if (<= \func_num_args() && null !== $request func_get_arg(0)) {
  77.             return $this->errorCount[spl_object_hash($request)] ?? 0;
  78.         }
  79.         return array_sum($this->errorCount);
  80.     }
  81.     /**
  82.      * {@inheritdoc}
  83.      */
  84.     public function clear()
  85.     {
  86.         $this->records = [];
  87.         $this->errorCount = [];
  88.     }
  89.     /**
  90.      * {@inheritdoc}
  91.      */
  92.     public function reset()
  93.     {
  94.         $this->clear();
  95.     }
  96. }