final class StateLogger in Preview Link 2.x
Same name and namespace in other branches
- 2.0.x tests/modules/preview_link_test/src/StateLogger.php \Drupal\preview_link_test\StateLogger
Sends logs to state.
Hierarchy
- class \Drupal\preview_link_test\StateLogger implements \Psr\Log\LoggerInterface uses \Psr\Log\LoggerTrait
Expanded class hierarchy of StateLogger
1 string reference to 'StateLogger'
- preview_link_test.services.yml in tests/
modules/ preview_link_test/ preview_link_test.services.yml - tests/modules/preview_link_test/preview_link_test.services.yml
1 service uses StateLogger
- logger.preview_link_test in tests/
modules/ preview_link_test/ preview_link_test.services.yml - Drupal\preview_link_test\StateLogger
File
- tests/
modules/ preview_link_test/ src/ StateLogger.php, line 13
Namespace
Drupal\preview_link_testView source
final class StateLogger implements LoggerInterface {
use LoggerTrait;
const STATE_LOGGER = 'state_preview_link_test_logs';
/**
* State.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;
/**
* StateLogger constructor.
*/
public function __construct(StateInterface $state) {
$this->state = $state;
}
/**
* {@inheritdoc}
*/
public function log($level, $message, array $context = []) {
$logs = $this
->getLogs();
$messagePlaceholders = (new LogMessageParser())
->parseMessagePlaceholders($message, $context);
$logs[] = [
$level,
$message,
$messagePlaceholders,
// Whitelist context keys to prevent serializing container, etc.
array_intersect_key($context, array_flip([
'channel',
])),
];
$this->state
->set(static::STATE_LOGGER, $logs);
}
/**
* Gets the captured logs.
*
* @return array
* An array of logs, which contain the arguments passed to log().
*/
public function getLogs() : array {
return $this->state
->get(static::STATE_LOGGER, []);
}
/**
* Deletes captured logs.
*/
public function cleanLogs() : void {
$this->state
->delete(static::STATE_LOGGER);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StateLogger:: |
protected | property | State. | |
StateLogger:: |
public | function | Deletes captured logs. | |
StateLogger:: |
public | function | Gets the captured logs. | |
StateLogger:: |
public | function | ||
StateLogger:: |
constant | |||
StateLogger:: |
public | function | StateLogger constructor. |