[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/maximebf/debugbar/src/DebugBar/Bridge/ -> SlimCollector.php (source)

   1  <?php
   2  /*
   3   * This file is part of the DebugBar package.
   4   *
   5   * (c) 2013 Maxime Bouroumeau-Fuseau
   6   *
   7   * For the full copyright and license information, please view the LICENSE
   8   * file that was distributed with this source code.
   9   */
  10  
  11  namespace DebugBar\Bridge;
  12  
  13  use DebugBar\DataCollector\MessagesCollector;
  14  use Psr\Log\LogLevel;
  15  use Slim\Log;
  16  use Slim\Slim;
  17  
  18  /**
  19   * Collects messages from a Slim logger
  20   *
  21   * http://slimframework.com
  22   */
  23  class SlimCollector extends MessagesCollector
  24  {
  25      protected $slim;
  26  
  27      protected $originalLogWriter;
  28  
  29      public function __construct(Slim $slim)
  30      {
  31          $this->slim = $slim;
  32          if ($log = $slim->getLog()) {
  33              $this->originalLogWriter = $log->getWriter();
  34              $log->setWriter($this);
  35              $log->setEnabled(true);
  36          }
  37      }
  38  
  39      public function write($message, $level)
  40      {
  41          if ($this->originalLogWriter) {
  42              $this->originalLogWriter->write($message, $level);
  43          }
  44          $this->addMessage($message, $this->getLevelName($level));
  45      }
  46  
  47      protected function getLevelName($level)
  48      {
  49          $map = array(
  50              Log::EMERGENCY => LogLevel::EMERGENCY,
  51              Log::ALERT => LogLevel::ALERT,
  52              Log::CRITICAL => LogLevel::CRITICAL,
  53              Log::ERROR => LogLevel::ERROR,
  54              Log::WARN => LogLevel::WARNING,
  55              Log::NOTICE => LogLevel::NOTICE,
  56              Log::INFO => LogLevel::INFO,
  57              Log::DEBUG => LogLevel::DEBUG
  58          );
  59          return $map[$level];
  60      }
  61  
  62      public function getName()
  63      {
  64          return 'slim';
  65      }
  66  }


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