You are here

public function LoggerService::get in Purge 8.3

Retrieve a channel part instance.

This creates a 'channel part' logger object compliant to the widely used \Psr\Log\LoggerInterface difference, with the difference that messages are funneled through a single channel and severities can be configured. Newly requested IDs will be automatically registered through ::setChannel().

Parameters

string $id: The identifier of the channel part.

Return value

\Drupal\purge\Logger\LoggerChannelPartInterface The channel part instance.

Throws

\LogicException Thrown when the given id is empty or otherwise invalid.

Overrides LoggerServiceInterface::get

File

src/Logger/LoggerService.php, line 141

Class

LoggerService
Provides logging services to purge and its submodules, via a single channel.

Namespace

Drupal\purge\Logger

Code

public function get($id) {
  if (!$this
    ->hasChannel($id)) {
    $this
      ->setChannel($id, [
      RfcLogLevel::EMERGENCY,
      RfcLogLevel::CRITICAL,
      RfcLogLevel::ERROR,
    ]);
  }
  if (!isset($this->channels[$id])) {
    $grants = [];
    foreach ($this->config as $channel) {
      if ($channel['id'] === $id) {
        $grants = $channel['grants'];
      }
    }
    $this->channels[$id] = $this->purgeLoggerPartsFactory
      ->create($id, $grants);
  }
  return $this->channels[$id];
}