class TestLogger in Configuration selector 8.2
Same name and namespace in other branches
- 8 src/TestLogger.php \Drupal\config_selector\TestLogger
A test logger.
Hierarchy
- class \Drupal\config_selector\TestLogger implements \Symfony\Component\HttpKernel\Log\DebugLoggerInterface, \Psr\Log\LoggerInterface
Expanded class hierarchy of TestLogger
1 file declares its use of TestLogger
- ConfigSelectorTest.php in tests/
src/ Kernel/ ConfigSelectorTest.php
File
- src/
TestLogger.php, line 14
Namespace
Drupal\config_selectorView source
class TestLogger implements DebugLoggerInterface, LoggerInterface {
/**
* An array of log messages keyed by type.
*
* @var array
*/
protected static $logs;
/**
* TestLogger constructor.
*/
public function __construct() {
if (empty(static::$logs)) {
$this
->clear();
}
}
/**
* {@inheritdoc}
*/
public function getLogs($level = FALSE) {
return FALSE === $level ? static::$logs : static::$logs[$level];
}
/**
* {@inheritdoc}
*/
public function clear() {
static::$logs = [
'emergency' => [],
'alert' => [],
'critical' => [],
'error' => [],
'warning' => [],
'notice' => [],
'info' => [],
'debug' => [],
];
}
/**
* {@inheritdoc}
*/
public function log($level, $message, array $context = []) {
// Convert levels...
static $map = [
RfcLogLevel::DEBUG => 'debug',
RfcLogLevel::INFO => 'info',
RfcLogLevel::NOTICE => 'notice',
RfcLogLevel::WARNING => 'warning',
RfcLogLevel::ERROR => 'error',
RfcLogLevel::CRITICAL => 'critical',
RfcLogLevel::ALERT => 'alert',
RfcLogLevel::EMERGENCY => 'emergency',
];
$level = isset($map[$level]) ? $map[$level] : $level;
static::$logs[$level][] = (string) new FormattableMarkup($message, $context);
}
/**
* {@inheritdoc}
*/
public function emergency($message, array $context = []) {
$this
->log('emergency', $message, $context);
}
/**
* {@inheritdoc}
*/
public function alert($message, array $context = []) {
$this
->log('alert', $message, $context);
}
/**
* {@inheritdoc}
*/
public function critical($message, array $context = []) {
$this
->log('critical', $message, $context);
}
/**
* {@inheritdoc}
*/
public function error($message, array $context = []) {
$this
->log('error', $message, $context);
}
/**
* {@inheritdoc}
*/
public function warning($message, array $context = []) {
$this
->log('warning', $message, $context);
}
/**
* {@inheritdoc}
*/
public function notice($message, array $context = []) {
$this
->log('notice', $message, $context);
}
/**
* {@inheritdoc}
*/
public function info($message, array $context = []) {
$this
->log('info', $message, $context);
}
/**
* {@inheritdoc}
*/
public function debug($message, array $context = []) {
$this
->log('debug', $message, $context);
}
/**
* Registers the test logger to the container.
*
* @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
* The ContainerBuilder to register the test logger to.
*/
public static function register(ContainerBuilder $container) {
$container
->register('config_selector.test_logger', __CLASS__)
->addTag('logger');
}
/**
* {@inheritdoc}
*/
public function countErrors() {
return count(static::$logs['critical']) + count(static::$logs['error']) + count(static::$logs['emergency']);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TestLogger:: |
protected static | property | An array of log messages keyed by type. | |
TestLogger:: |
public | function | Action must be taken immediately. | |
TestLogger:: |
public | function | ||
TestLogger:: |
public | function | Returns the number of errors. | |
TestLogger:: |
public | function | Critical conditions. | |
TestLogger:: |
public | function | Detailed debug information. | |
TestLogger:: |
public | function | System is unusable. | |
TestLogger:: |
public | function | Runtime errors that do not require immediate action but should typically be logged and monitored. | |
TestLogger:: |
public | function | Returns an array of logs. | |
TestLogger:: |
public | function | Interesting events. | |
TestLogger:: |
public | function | Logs with an arbitrary level. | |
TestLogger:: |
public | function | Normal but significant events. | |
TestLogger:: |
public static | function | Registers the test logger to the container. | |
TestLogger:: |
public | function | Exceptional occurrences that are not errors. | |
TestLogger:: |
public | function | TestLogger constructor. |