RulesLog.php in Rules 8.3
File
src/Logger/RulesLog.php
View source
<?php
namespace Drupal\rules\Logger;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Logger\LogMessageParserInterface;
use Drupal\Core\Logger\RfcLoggerTrait;
use Drupal\rules\Event\SystemLoggerEvent;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class RulesLog implements LoggerInterface {
use RfcLoggerTrait;
use DependencySerializationTrait;
protected $dispatcher;
protected $parser;
public function __construct(EventDispatcherInterface $dispatcher, LogMessageParserInterface $parser) {
$this->dispatcher = $dispatcher;
$this->parser = $parser;
}
public function log($level, $message, array $context = []) {
unset($context['backtrace']);
$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'],
];
$event = new SystemLoggerEvent($logger_entry, [
'logger_entry' => $logger_entry,
]);
$this->dispatcher
->dispatch(SystemLoggerEvent::EVENT_NAME, $event);
}
}
Classes
Name |
Description |
RulesLog |
Logger that dispatches a SystemLoggerEvent when a logger entry is made. |