[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/maximebf/debugbar/src/DebugBar/Bridge/ -> MonologCollector.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\DataCollectorInterface;
  14  use DebugBar\DataCollector\MessagesAggregateInterface;
  15  use DebugBar\DataCollector\Renderable;
  16  use Monolog\Handler\AbstractProcessingHandler;
  17  use Monolog\Logger;
  18  
  19  /**
  20   * A monolog handler as well as a data collector
  21   *
  22   * https://github.com/Seldaek/monolog
  23   *
  24   * <code>
  25   * $debugbar->addCollector(new MonologCollector($logger));
  26   * </code>
  27   */
  28  class MonologCollector extends AbstractProcessingHandler implements DataCollectorInterface, Renderable, MessagesAggregateInterface
  29  {
  30      protected $name;
  31  
  32      protected $records = array();
  33  
  34      /**
  35       * @param Logger $logger
  36       * @param int $level
  37       * @param boolean $bubble
  38       * @param string $name
  39       */
  40      public function __construct(Logger $logger = null, $level = Logger::DEBUG, $bubble = true, $name = 'monolog')
  41      {
  42          parent::__construct($level, $bubble);
  43          $this->name = $name;
  44          if ($logger !== null) {
  45              $this->addLogger($logger);
  46          }
  47      }
  48  
  49      /**
  50       * Adds logger which messages you want to log
  51       *
  52       * @param Logger $logger
  53       */
  54      public function addLogger(Logger $logger)
  55      {
  56          $logger->pushHandler($this);
  57      }
  58  
  59      /**
  60       * @param array $record
  61       */
  62      protected function write(array $record): void
  63      {
  64          $this->records[] = array(
  65              'message' => $record['formatted'],
  66              'is_string' => true,
  67              'label' => strtolower($record['level_name']),
  68              'time' => $record['datetime']->format('U')
  69          );
  70      }
  71  
  72      /**
  73       * @return array
  74       */
  75      public function getMessages()
  76      {
  77          return $this->records;
  78      }
  79  
  80      /**
  81       * @return array
  82       */
  83      public function collect()
  84      {
  85          return array(
  86              'count' => count($this->records),
  87              'records' => $this->records
  88          );
  89      }
  90  
  91      /**
  92       * @return string
  93       */
  94      public function getName()
  95      {
  96          return $this->name;
  97      }
  98  
  99      /**
 100       * @return array
 101       */
 102      public function getWidgets()
 103      {
 104          $name = $this->getName();
 105          return array(
 106              $name => array(
 107                  "icon" => "suitcase",
 108                  "widget" => "PhpDebugBar.Widgets.MessagesWidget",
 109                  "map" => "$name.records",
 110                  "default" => "[]"
 111              ),
 112              "$name:badge" => array(
 113                  "map" => "$name.count",
 114                  "default" => "null"
 115              )
 116          );
 117      }
 118  }


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