class RulesLog

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

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

Hierarchy

Expanded class hierarchy of RulesLog

1 string reference to 'RulesLog'
rules.services.yml in ./rules.services.yml
rules.services.yml
1 service uses RulesLog
logger.ruleslog in ./rules.services.yml
Drupal\rules\Logger\RulesLog

File

src/Logger/RulesLog.php, line 15

Namespace

Drupal\rules\Logger
View source
class RulesLog implements LoggerInterface {
    use RfcLoggerTrait;
    use DependencySerializationTrait;
    
    /**
     * The event_dispatcher service.
     *
     * @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface
     */
    protected $dispatcher;
    
    /**
     * The message's placeholders parser.
     *
     * @var \Drupal\Core\Logger\LogMessageParserInterface
     */
    protected $parser;
    
    /**
     * Constructs a new instance.
     *
     * @param \Symfony\Contracts\EventDispatcher\EventDispatcherInterface $dispatcher
     *   The event_dispatcher service.
     * @param \Drupal\Core\Logger\LogMessageParserInterface $parser
     *   The parser to use when extracting message variables.
     */
    public function __construct(EventDispatcherInterface $dispatcher, LogMessageParserInterface $parser) {
        $this->dispatcher = $dispatcher;
        $this->parser = $parser;
    }
    
    /**
     * {@inheritdoc}
     *
     * @todo Create a TypedData logger-entry object.
     * @see https://www.drupal.org/node/2625238
     */
    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);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
RfcLoggerTrait::alert public function
RfcLoggerTrait::critical public function
RfcLoggerTrait::debug public function
RfcLoggerTrait::emergency public function
RfcLoggerTrait::error public function
RfcLoggerTrait::info public function
RfcLoggerTrait::notice public function
RfcLoggerTrait::warning public function
RulesLog::$dispatcher protected property The event_dispatcher service.
RulesLog::$parser protected property The message's placeholders parser.
RulesLog::log public function @todo Create a TypedData logger-entry object. Overrides RfcLoggerTrait::log
RulesLog::__construct public function Constructs a new instance.