class LoggerChannel in Service Container 7.2
Same name and namespace in other branches
- 7 src/Logger/LoggerChannel.php \Drupal\service_container\Logger\LoggerChannel
Defines a logger channel that most implementations will use.
Hierarchy
- class \Drupal\service_container\Logger\LoggerBase implements LoggerInterface
- class \Drupal\service_container\Logger\LoggerChannel implements LoggerChannelInterface
Expanded class hierarchy of LoggerChannel
1 file declares its use of LoggerChannel
- LoggerChannelTest.php in tests/
src/ Logger/ LoggerChannelTest.php - Contains \Drupal\Tests\service_container\Logger\LoggerChannelTest.
File
- src/
Logger/ LoggerChannel.php, line 18 - Contains \Drupal\service_container\Logger\LoggerChannel.
Namespace
Drupal\service_container\LoggerView source
class LoggerChannel extends LoggerBase implements LoggerChannelInterface {
/**
* The name of the channel of this logger instance.
*
* @var string
*/
protected $channel;
/**
* An array of arrays of \Psr\Log\LoggerInterface keyed by priority.
*
* @var array
*/
protected $loggers = array();
/**
* The request stack object.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The current user object.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* {@inheritdoc}
*/
public function log($level, $message, array $context = array()) {
$context += array(
'channel' => $this->channel,
);
// @codeCoverageIgnore
foreach ($this
->sortLoggers() as $logger) {
$logger
->log($level, $message, $context);
}
}
/**
* Constructs a LoggerChannel object
*
* @param string $channel
* The channel name for this instance.
*/
public function __construct($channel) {
$this->channel = $channel;
}
/**
* {@inheritdoc}
*/
public function setLoggers(array $loggers) {
$this->loggers = $loggers;
}
/**
* {@inheritdoc}
*/
public function addLogger(LoggerInterface $logger, $priority = 0) {
$this->loggers[$priority][] = $logger;
}
/**
* Sorts loggers according to priority.
*
* @return array
* An array of sorted loggers by priority.
*/
protected function sortLoggers() {
$sorted = array();
krsort($this->loggers);
foreach ($this->loggers as $loggers) {
$sorted = array_merge($sorted, $loggers);
}
return $sorted;
}
/**
* {@inheritdoc}
*/
public function setRequestStack(RequestStack $requestStack = NULL) {
$this->requestStack = $requestStack;
}
/**
* {@inheritdoc}
*/
public function setCurrentUser(AccountInterface $current_user = NULL) {
$this->currentUser = $current_user;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LoggerBase:: |
public | function |
Action must be taken immediately. Overrides LoggerInterface:: |
|
LoggerBase:: |
public | function |
Critical conditions. Overrides LoggerInterface:: |
|
LoggerBase:: |
public | function |
Detailed debug information. Overrides LoggerInterface:: |
|
LoggerBase:: |
public | function |
System is unusable. Overrides LoggerInterface:: |
|
LoggerBase:: |
public | function |
Runtime errors that do not require immediate action but should typically
be logged and monitored. Overrides LoggerInterface:: |
|
LoggerBase:: |
public | function |
Interesting events. Overrides LoggerInterface:: |
|
LoggerBase:: |
public | function |
Normal but significant events. Overrides LoggerInterface:: |
|
LoggerBase:: |
public | function |
Exceptional occurrences that are not errors. Overrides LoggerInterface:: |
|
LoggerChannel:: |
protected | property | The name of the channel of this logger instance. | |
LoggerChannel:: |
protected | property | The current user object. | |
LoggerChannel:: |
protected | property | An array of arrays of \Psr\Log\LoggerInterface keyed by priority. | |
LoggerChannel:: |
protected | property | The request stack object. | |
LoggerChannel:: |
public | function |
Adds a logger. Overrides LoggerChannelInterface:: |
|
LoggerChannel:: |
public | function |
Logs with an arbitrary level. Overrides LoggerInterface:: |
|
LoggerChannel:: |
public | function |
Sets the current user. Overrides LoggerChannelInterface:: |
|
LoggerChannel:: |
public | function |
Sets the loggers for this channel. Overrides LoggerChannelInterface:: |
|
LoggerChannel:: |
public | function |
Sets the request stack. Overrides LoggerChannelInterface:: |
|
LoggerChannel:: |
protected | function | Sorts loggers according to priority. | |
LoggerChannel:: |
public | function | Constructs a LoggerChannel object |