function RulesDebugLog::log

File

src/Logger/RulesDebugLog.php, line 51

Class

RulesDebugLog
Logger that stores Rules debug logs with the session service.

Namespace

Drupal\rules\Logger

Code

public function log($level, $message, array $context = []) : void {
    // Remove any backtraces since they may contain an unserializable variable.
    unset($context['backtrace']);
    $localCopy = $this->session
        ->get('rules_debug_log', []);
    // Append the new log to the $localCopy array.
    // In D7:
    // @code
    //   logs[] = [$msg, $args, $priority, microtime(TRUE), $scope, $path];
    // @endcode
    $localCopy[] = [
        'message' => $message,
        'context' => $context,
        
        /** @var \Psr\Log\LogLevel $level */
'level' => $level,
        'timestamp' => $context['timestamp'],
        'scope' => $context['scope'],
        'path' => $context['path'],
    ];
    // Write the $localCopy array back into the session;
    // it now includes the new log.
    $this->session
        ->set('rules_debug_log', $localCopy);
}