public function LoggerService::setChannel in Purge 8.3
Add or update a channel part and its permissions.
Parameters
string $id: The identifier of the channel part.
int[] $grants: Unassociative array of RFC 5424 log types. Each passed type grants the channel permission to log that type of message, without specific permissions the logger will stay silent for that type.
Grants available:
- \Drupal\Core\Logger\RfcLogLevel::EMERGENCY
- \Drupal\Core\Logger\RfcLogLevel::ALERT
- \Drupal\Core\Logger\RfcLogLevel::CRITICAL
- \Drupal\Core\Logger\RfcLogLevel::ERROR
- \Drupal\Core\Logger\RfcLogLevel::WARNING
- \Drupal\Core\Logger\RfcLogLevel::NOTICE
- \Drupal\Core\Logger\RfcLogLevel::INFO
- \Drupal\Core\Logger\RfcLogLevel::DEBUG.
Throws
\LogicException Thrown when the given id is empty or otherwise invalid.
\LogicException Thrown when any given grant isn't known or otherwise invalid.
Overrides LoggerServiceInterface::setChannel
1 call to LoggerService::setChannel()
- LoggerService::get in src/
Logger/ LoggerService.php - Retrieve a channel part instance.
File
- src/
Logger/ LoggerService.php, line 183
Class
- LoggerService
- Provides logging services to purge and its submodules, via a single channel.
Namespace
Drupal\purge\LoggerCode
public function setChannel($id, array $grants = []) {
// Perform input validation.
if (empty($id) || !is_string($id)) {
throw new \LogicException('The given ID is empty or not a string!');
}
foreach ($grants as $grant) {
if (!in_array($grant, $this->grants)) {
throw new \LogicException("Passed grant is invalid!");
}
}
// Determine the config index that we'll write to (existing or new).
$i = end($this->config) ? key($this->config) + 1 : 0;
foreach ($this->config as $index => $channel) {
if ($channel['id'] === $id) {
$i = $index;
break;
}
}
// (Over)write the channel and its grants.
$this->config[$i] = [
'id' => $id,
'grants' => $grants,
];
$this->write = TRUE;
}