class RulesLog in Rules 8.3
Logger that dispatches a SystemLoggerEvent when a logger entry is made.
Hierarchy
- class \Drupal\rules\Logger\RulesLog implements \Psr\Log\LoggerInterface uses DependencySerializationTrait, RfcLoggerTrait
Expanded class hierarchy of RulesLog
1 string reference to 'RulesLog'
1 service uses RulesLog
File
- src/
Logger/ RulesLog.php, line 15
Namespace
Drupal\rules\LoggerView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RulesLog:: |
protected | property | The dispatcher. | |
RulesLog:: |
protected | property | The message's placeholders parser. | |
RulesLog:: |
public | function |
@todo Create a TypedData logger-entry object. Overrides RfcLoggerTrait:: |
|
RulesLog:: |
public | function | Constructs a new instance. |