You are here

public function StateLogger::log in Preview Link 2.x

Same name and namespace in other branches
  1. 2.0.x tests/modules/preview_link_test/src/StateLogger.php \Drupal\preview_link_test\StateLogger::log()

File

tests/modules/preview_link_test/src/StateLogger.php, line 36

Class

StateLogger
Sends logs to state.

Namespace

Drupal\preview_link_test

Code

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);
}