LoggerChannel.php in TMGMT Translator Smartling 8.4
File
modules/tmgmt_smartling_log_settings/src/Logger/LoggerChannel.php
View source
<?php
namespace Drupal\tmgmt_smartling_log_settings\Logger;
use Drupal\Core\Logger\LoggerChannel as LoggerChannelCore;
use Drupal\Core\Logger\RfcLogLevel;
use Drupal\Core\Serialization\Yaml;
class LoggerChannel extends LoggerChannelCore {
private $severity_mapping;
public function __construct($channel) {
$severity_mapping =& drupal_static(get_called_class());
if (!isset($severity_mapping)) {
$config = \Drupal::configFactory()
->getEditable('tmgmt_smartling_log_settings.settings')
->get('severity_mapping');
$severity_mapping = Yaml::decode($config);
}
$this->severity_mapping = $severity_mapping;
parent::__construct($channel);
}
public function log($level, $message, array $context = []) {
if ($this->callDepth == self::MAX_CALL_DEPTH) {
return;
}
$this->callDepth++;
$context += [
'channel' => $this->channel,
'link' => '',
'user' => NULL,
'uid' => 0,
'request_uri' => '',
'referer' => '',
'ip' => '',
'timestamp' => time(),
];
if ($this->requestStack && ($request = $this->requestStack
->getCurrentRequest())) {
$context['request_uri'] = $request
->getUri();
$context['referer'] = $request->headers
->get('Referer', '');
$context['ip'] = $request
->getClientIP();
try {
if ($this->currentUser) {
$context['user'] = $this->currentUser;
$context['uid'] = $this->currentUser
->id();
}
} catch (\Exception $e) {
}
}
if (is_string($level)) {
$level = $this->levelTranslation[$level];
}
foreach ($this
->sortLoggers() as $logger) {
$logger_class = get_class($logger);
if ($logger_class == 'Drupal\\tmgmt_smartling\\Logger\\BufferLogger') {
$logger
->log($level, $message, $context);
}
else {
$config_level = !empty($this->severity_mapping[$this->channel]) ? $this->levelTranslation[$this->severity_mapping[$this->channel]] : RfcLogLevel::DEBUG;
if (!empty($this->severity_mapping[$this->channel])) {
if ($level <= $config_level) {
$logger
->log($level, $message, $context);
}
}
else {
$logger
->log($level, $message, $context);
}
}
}
$this->callDepth--;
}
}
Classes
Name |
Description |
LoggerChannel |
Defines a logger channel that most implementations will use. |