[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/symfony/error-handler/ -> BufferingLogger.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <[email protected]>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Component\ErrorHandler;
  13  
  14  use Psr\Log\AbstractLogger;
  15  
  16  /**
  17   * A buffering logger that stacks logs for later.
  18   *
  19   * @author Nicolas Grekas <[email protected]>
  20   */
  21  class BufferingLogger extends AbstractLogger
  22  {
  23      private $logs = [];
  24  
  25      public function log($level, $message, array $context = []): void
  26      {
  27          $this->logs[] = [$level, $message, $context];
  28      }
  29  
  30      public function cleanLogs(): array
  31      {
  32          $logs = $this->logs;
  33          $this->logs = [];
  34  
  35          return $logs;
  36      }
  37  
  38      /**
  39       * @return array
  40       */
  41      public function __sleep()
  42      {
  43          throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
  44      }
  45  
  46      public function __wakeup()
  47      {
  48          throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
  49      }
  50  
  51      public function __destruct()
  52      {
  53          foreach ($this->logs as [$level, $message, $context]) {
  54              if (false !== strpos($message, '{')) {
  55                  foreach ($context as $key => $val) {
  56                      if (null === $val || is_scalar($val) || (\is_object($val) && \is_callable([$val, '__toString']))) {
  57                          $message = str_replace("{{$key}}", $val, $message);
  58                      } elseif ($val instanceof \DateTimeInterface) {
  59                          $message = str_replace("{{$key}}", $val->format(\DateTime::RFC3339), $message);
  60                      } elseif (\is_object($val)) {
  61                          $message = str_replace("{{$key}}", '[object '.\get_class($val).']', $message);
  62                      } else {
  63                          $message = str_replace("{{$key}}", '['.\gettype($val).']', $message);
  64                      }
  65                  }
  66              }
  67  
  68              error_log(sprintf('%s [%s] %s', date(\DateTime::RFC3339), $level, $message));
  69          }
  70      }
  71  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer