class LoggerDataCollector

LogDataCollector.

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

Expanded class hierarchy of LoggerDataCollector

1 file declares its use of LoggerDataCollector
LoggerDataCollectorTest.php in drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php

File

drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php, line 24

Namespace

Symfony\Component\HttpKernel\DataCollector
View source
class LoggerDataCollector extends DataCollector {
  private $logger;
  public function __construct($logger = null) {
    if (null !== $logger && $logger instanceof DebugLoggerInterface) {
      $this->logger = $logger;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function collect(Request $request, Response $response, \Exception $exception = null) {
    if (null !== $this->logger) {
      $this->data = array(
        'error_count' => $this->logger
          ->countErrors(),
        'logs' => $this
          ->sanitizeLogs($this->logger
          ->getLogs()),
        'deprecation_count' => $this
          ->computeDeprecationCount(),
      );
    }
  }

  /**
   * Gets the called events.
   *
   * @return array An array of called events
   *
   * @see TraceableEventDispatcherInterface
   */
  public function countErrors() {
    return isset($this->data['error_count']) ? $this->data['error_count'] : 0;
  }

  /**
   * Gets the logs.
   *
   * @return array An array of logs
   */
  public function getLogs() {
    return isset($this->data['logs']) ? $this->data['logs'] : array();
  }
  public function countDeprecations() {
    return isset($this->data['deprecation_count']) ? $this->data['deprecation_count'] : 0;
  }

  /**
   * {@inheritdoc}
   */
  public function getName() {
    return 'logger';
  }
  private function sanitizeLogs($logs) {
    foreach ($logs as $i => $log) {
      $logs[$i]['context'] = $this
        ->sanitizeContext($log['context']);
    }
    return $logs;
  }
  private function sanitizeContext($context) {
    if (is_array($context)) {
      foreach ($context as $key => $value) {
        $context[$key] = $this
          ->sanitizeContext($value);
      }
      return $context;
    }
    if (is_resource($context)) {
      return sprintf('Resource(%s)', get_resource_type($context));
    }
    if (is_object($context)) {
      return sprintf('Object(%s)', get_class($context));
    }
    return $context;
  }
  private function computeDeprecationCount() {
    $count = 0;
    foreach ($this->logger
      ->getLogs() as $log) {
      if (isset($log['context']['type']) && ErrorHandler::TYPE_DEPRECATION === $log['context']['type']) {
        $count++;
      }
    }
    return $count;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DataCollector::$data protected property
DataCollector::serialize public function
DataCollector::unserialize public function
DataCollector::varToString protected function Converts a PHP variable to a string.
LoggerDataCollector::$logger private property
LoggerDataCollector::collect public function Collects data for the given Request and Response. Overrides DataCollectorInterface::collect
LoggerDataCollector::computeDeprecationCount private function
LoggerDataCollector::countDeprecations public function
LoggerDataCollector::countErrors public function Gets the called events.
LoggerDataCollector::getLogs public function Gets the logs.
LoggerDataCollector::getName public function Returns the name of the collector. Overrides DataCollectorInterface::getName
LoggerDataCollector::sanitizeContext private function
LoggerDataCollector::sanitizeLogs private function
LoggerDataCollector::__construct public function