You are here

class LoggerChannelFactory in Service Container 7.2

Same name and namespace in other branches
  1. 7 src/Logger/LoggerChannelFactory.php \Drupal\service_container\Logger\LoggerChannelFactory

Defines a factory for logging channels.

Hierarchy

Expanded class hierarchy of LoggerChannelFactory

1 file declares its use of LoggerChannelFactory
LoggerChannelFactoryTest.php in tests/src/Logger/LoggerChannelFactoryTest.php
Contains \Drupal\Tests\service_container\Logger\LoggerChannelFactoryTest.

File

src/Logger/LoggerChannelFactory.php, line 16
Contains \Drupal\service_container\Logger\LoggerChannelFactory.

Namespace

Drupal\service_container\Logger
View source
class LoggerChannelFactory implements LoggerChannelFactoryInterface {

  /**
   * 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);

      // 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
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