function LoggerChannelFactory::get

Same name in other branches
  1. 9 core/lib/Drupal/Core/Logger/LoggerChannelFactory.php \Drupal\Core\Logger\LoggerChannelFactory::get()
  2. 8.9.x core/lib/Drupal/Core/Logger/LoggerChannelFactory.php \Drupal\Core\Logger\LoggerChannelFactory::get()
  3. 11.x core/lib/Drupal/Core/Logger/LoggerChannelFactory.php \Drupal\Core\Logger\LoggerChannelFactory::get()

File

core/lib/Drupal/Core/Logger/LoggerChannelFactory.php, line 65

Class

LoggerChannelFactory
Defines a factory for logging channels.

Namespace

Drupal\Core\Logger

Code

public function get($channel) {
    if (!$this->requestStack || !$this->currentUser) {
        @trigger_error('Calling ' . __METHOD__ . ' without calling the constructor is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3416354', E_USER_DEPRECATED);
        $this->requestStack = \Drupal::service('request_stack');
        $this->currentUser = \Drupal::service('current_user');
    }
    if (!isset($this->channels[$channel])) {
        $instance = new LoggerChannel($channel);
        // 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.
        $instance->setRequestStack($this->requestStack);
        $instance->setCurrentUser($this->currentUser);
        // Pass the loggers to the channel.
        $instance->setLoggers($this->loggers);
        $this->channels[$channel] = $instance;
    }
    return $this->channels[$channel];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.