LoggerChannel.php in Service Container 7.2
File
src/Logger/LoggerChannel.php
View source
<?php
namespace Drupal\service_container\Logger;
use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\Core\Session\AccountInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class LoggerChannel extends LoggerBase implements LoggerChannelInterface {
protected $channel;
protected $loggers = array();
protected $requestStack;
protected $currentUser;
public function log($level, $message, array $context = array()) {
$context += array(
'channel' => $this->channel,
);
foreach ($this
->sortLoggers() as $logger) {
$logger
->log($level, $message, $context);
}
}
public function __construct($channel) {
$this->channel = $channel;
}
public function setLoggers(array $loggers) {
$this->loggers = $loggers;
}
public function addLogger(LoggerInterface $logger, $priority = 0) {
$this->loggers[$priority][] = $logger;
}
protected function sortLoggers() {
$sorted = array();
krsort($this->loggers);
foreach ($this->loggers as $loggers) {
$sorted = array_merge($sorted, $loggers);
}
return $sorted;
}
public function setRequestStack(RequestStack $requestStack = NULL) {
$this->requestStack = $requestStack;
}
public function setCurrentUser(AccountInterface $current_user = NULL) {
$this->currentUser = $current_user;
}
}
Classes
Name |
Description |
LoggerChannel |
Defines a logger channel that most implementations will use. |