You are here

public function MonologLoggerChannelFactory::get in Monolog 8

Same name and namespace in other branches
  1. 2.x src/Logger/MonologLoggerChannelFactory.php \Drupal\monolog\Logger\MonologLoggerChannelFactory::get()

Retrieves the registered logger for the requested channel.

Return value

\Drupal\Core\Logger\LoggerChannelInterface The registered logger for this channel.

Overrides LoggerChannelFactoryInterface::get

File

src/Logger/MonologLoggerChannelFactory.php, line 34

Class

MonologLoggerChannelFactory
Defines a factory for logging channels.

Namespace

Drupal\monolog\Logger

Code

public function get($channel) {
  if (!isset($this->channels[$channel])) {
    try {
      $this->channels[$channel] = $this
        ->getChannelInstance($channel);
    } catch (\InvalidArgumentException $e) {
      $this->channels[$channel] = new NullLogger();
      if ($this->container
        ->get('current_user')
        ->hasPermission('administer site configuration')) {
        \Drupal::messenger()
          ->addError($e
          ->getMessage());
      }
    }
  }
  return $this->channels[$channel];
}