You are here

class RulesLog in Rules 8.3

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 dispatcher.
   *
   * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
   */
  protected $dispatcher;

  /**
   * The message's placeholders parser.
   *
   * @var \Drupal\Core\Logger\LogMessageParserInterface
   */
  protected $parser;

  /**
   * Constructs a new instance.
   *
   * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
   *   An EventDispatcherInterface instance.
   * @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 = []) {

    // 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(SystemLoggerEvent::EVENT_NAME, $event);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
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 dispatcher.
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.