class ErrorLog in Error Log 8
Logs events to the PHP error log.
Hierarchy
- class \Drupal\error_log\Logger\ErrorLog implements \Psr\Log\LoggerInterface uses DependencySerializationTrait, RfcLoggerTrait
Expanded class hierarchy of ErrorLog
1 string reference to 'ErrorLog'
1 service uses ErrorLog
File
- src/
Logger/ ErrorLog.php, line 15
Namespace
Drupal\error_log\LoggerView source
class ErrorLog implements LoggerInterface {
use DependencySerializationTrait {
__sleep as protected dependencySleep;
__wakeup as protected dependencyWakeup;
}
use RfcLoggerTrait;
/**
* Provides untranslated log levels.
*/
const LOG_LEVELS = [
RfcLogLevel::EMERGENCY => 'emergency',
RfcLogLevel::ALERT => 'alert',
RfcLogLevel::CRITICAL => 'critical',
RfcLogLevel::ERROR => 'error',
RfcLogLevel::WARNING => 'warning',
RfcLogLevel::NOTICE => 'notice',
RfcLogLevel::INFO => 'info',
RfcLogLevel::DEBUG => 'debug',
];
/**
* A configuration object containing syslog settings.
*
* @var \Drupal\Core\Config\Config
*/
protected $config;
/**
* Config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The message's placeholders parser.
*
* @var \Drupal\Core\Logger\LogMessageParserInterface
*/
protected $parser;
/**
* Constructs an Error Log object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory object.
* @param \Drupal\Core\Logger\LogMessageParserInterface $parser
* The parser to use when extracting message variables.
*/
public function __construct(ConfigFactoryInterface $config_factory, LogMessageParserInterface $parser) {
$this->configFactory = $config_factory;
$this->config = $this->configFactory
->get('error_log.settings');
$this->parser = $parser;
}
/**
* {@inheritdoc}
*/
public function log($level, $message, array $context = []) {
if (empty($this->config
->get('log_levels')["level_{$level}"])) {
return;
}
if (in_array($context['channel'], $this->config
->get('ignored_channels') ?: [])) {
return;
}
// Drush handles error logging for us, so disable redundant logging.
if (function_exists('drush_main') && !ini_get('error_log')) {
return;
}
$level = static::LOG_LEVELS[$level];
$message_placeholders = $this->parser
->parseMessagePlaceholders($message, $context);
$message = empty($message_placeholders) ? $message : strtr($message, $message_placeholders);
$message = "[{$level}] [{$context['channel']}] [{$context['ip']}] [uid:{$context['uid']}] [{$context['request_uri']}] [{$context['referer']}] {$message}";
error_log($message);
}
/**
* {@inheritdoc}
*/
public function __sleep() {
return array_diff($this
->dependencySleep(), [
'config',
]);
}
/**
* {@inheritdoc}
*/
public function __wakeup() {
$this
->dependencyWakeup();
$this->config = $this->configFactory
->get('error_log.settings');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | Aliased as: dependencySleep | 1 |
DependencySerializationTrait:: |
public | function | Aliased as: dependencyWakeup | 2 |
ErrorLog:: |
protected | property | A configuration object containing syslog settings. | |
ErrorLog:: |
protected | property | Config factory. | |
ErrorLog:: |
protected | property | The message's placeholders parser. | |
ErrorLog:: |
public | function |
Overrides RfcLoggerTrait:: |
|
ErrorLog:: |
constant | Provides untranslated log levels. | ||
ErrorLog:: |
public | function | Constructs an Error Log object. | |
ErrorLog:: |
public | function | ||
ErrorLog:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function |