You are here

class LoggerChannelFactory in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Logger/LoggerChannelFactory.php \Drupal\Core\Logger\LoggerChannelFactory

Defines a factory for logging channels.

Hierarchy

Expanded class hierarchy of LoggerChannelFactory

2 files declare their use of LoggerChannelFactory
install.core.inc in core/includes/install.core.inc
API functions for installing Drupal.
LoggerChannelFactoryTest.php in core/tests/Drupal/Tests/Core/Logger/LoggerChannelFactoryTest.php
Contains \Drupal\Tests\Core\Logger\LoggerChannelFactoryTest.
1 string reference to 'LoggerChannelFactory'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses LoggerChannelFactory
logger.factory in core/core.services.yml
Drupal\Core\Logger\LoggerChannelFactory

File

core/lib/Drupal/Core/Logger/LoggerChannelFactory.php, line 17
Contains \Drupal\Core\Logger\LoggerChannelFactory.

Namespace

Drupal\Core\Logger
View source
class LoggerChannelFactory implements LoggerChannelFactoryInterface, ContainerAwareInterface {
  use ContainerAwareTrait;

  /**
   * Array of all instantiated logger channels keyed by channel name.
   *
   * @var \Drupal\Core\Logger\LoggerChannelInterface[]
   */
  protected $channels = array();

  /**
   * An array of arrays of \Psr\Log\LoggerInterface keyed by priority.
   *
   * @var array
   */
  protected $loggers = array();

  /**
   * {@inheritdoc}
   */
  public function get($channel) {
    if (!isset($this->channels[$channel])) {
      $instance = new LoggerChannel($channel);

      // If we have a container set the request_stack and current_user services
      // on the channel. It is up to the channel to determine if there is a
      // current request.
      if ($this->container) {
        $instance
          ->setRequestStack($this->container
          ->get('request_stack'));
        $instance
          ->setCurrentUser($this->container
          ->get('current_user'));
      }

      // Pass the loggers to the channel.
      $instance
        ->setLoggers($this->loggers);
      $this->channels[$channel] = $instance;
    }
    return $this->channels[$channel];
  }

  /**
   * {@inheritdoc}
   */
  public function addLogger(LoggerInterface $logger, $priority = 0) {

    // Store it so we can pass it to potential new logger instances.
    $this->loggers[$priority][] = $logger;

    // Add the logger to already instantiated channels.
    foreach ($this->channels as $channel) {
      $channel
        ->addLogger($logger, $priority);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContainerAwareTrait::$container protected property
ContainerAwareTrait::setContainer public function Sets the Container associated with this Controller.
LoggerChannelFactory::$channels protected property Array of all instantiated logger channels keyed by channel name.
LoggerChannelFactory::$loggers protected property An array of arrays of \Psr\Log\LoggerInterface keyed by priority.
LoggerChannelFactory::addLogger public function Adds a logger. Overrides LoggerChannelFactoryInterface::addLogger
LoggerChannelFactory::get public function Retrieves the registered logger for the requested channel. Overrides LoggerChannelFactoryInterface::get