function RulesLog::log

Same name in other branches
  1. 7.x-2.x includes/rules.core.inc \RulesLog::log()

@todo Create a TypedData logger-entry object.

Overrides RfcLoggerTrait::log

See also

https://www.drupal.org/node/2625238

File

src/Logger/RulesLog.php, line 52

Class

RulesLog
Logger that dispatches a SystemLoggerEvent when a logger entry is made.

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']);
    // Convert PSR3-style messages to \Drupal\Component\Render\FormattableMarkup
    // style, so they can be translated at runtime.
    $message_placeholders = $this->parser
        ->parseMessagePlaceholders($message, $context);
    $logger_entry = [
        'uid' => $context['uid'],
        'type' => $context['channel'],
        'message' => $message,
        'variables' => $message_placeholders,
        'severity' => $level,
        'link' => $context['link'],
        'location' => $context['request_uri'],
        'referer' => $context['referer'],
        'hostname' => $context['ip'],
        'timestamp' => $context['timestamp'],
    ];
    // Dispatch logger_entry event.
    $event = new SystemLoggerEvent($logger_entry, [
        'logger_entry' => $logger_entry,
    ]);
    $this->dispatcher
        ->dispatch($event, SystemLoggerEvent::EVENT_NAME);
}