-
Notifications
You must be signed in to change notification settings - Fork 122
class \Drupal\rules\Plugin\DataType\LoggerEntry #315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 8.x-3.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
use Drupal\Core\Logger\LogMessageParserInterface; | ||
use Drupal\Core\Logger\RfcLoggerTrait; | ||
use Drupal\rules\Event\SystemLoggerEvent; | ||
use Drupal\rules\Plugin\DataType\LoggerEntry; | ||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
|
||
|
@@ -72,6 +73,10 @@ public function log($level, $message, array $context = array()) { | |
'timestamp' => $context['timestamp'], | ||
); | ||
|
||
$logger_entry = new LoggerEntry(); | ||
$logger_entry->log($level, $message, $context, $this->parser); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logger entry should not have a log() method. It should have a setMessage() method, a setLevel() method etc. |
||
|
||
|
||
// Dispatch logger_entry event. | ||
$event = new SystemLoggerEvent($logger_entry, ['logger_entry' => $logger_entry]); | ||
$this->dispatcher->dispatch(SystemLoggerEvent::EVENT_NAME, $event); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\rules\Plugin\DataType\LoggerEntry. | ||
*/ | ||
|
||
namespace Drupal\rules\Plugin\DataType; | ||
|
||
use Drupal\Core\Logger\LogMessageParserInterface; | ||
use Drupal\Core\TypedData\Plugin\DataType\Map; | ||
use Drupal\Core\TypedData\TypedData; | ||
use Drupal\Component\Utility\Random; | ||
use Drupal\Core\Field\FieldDefinitionInterface; | ||
use Drupal\Core\Field\FieldItemBase; | ||
use Drupal\Core\Field\FieldStorageDefinitionInterface; | ||
use Drupal\Core\Form\FormStateInterface; | ||
use Drupal\Core\TypedData\DataDefinition; | ||
use Drupal\Core\TypedData\MapDataDefinition; | ||
use Drupal\Core\Url; | ||
use Drupal\link\LinkItemInterface; | ||
|
||
/** | ||
* The logger entry data type. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we describe what this is? Example "Represents a log entry that is created from system log messages." |
||
* | ||
* Represents a log entry that is created from system log messages. | ||
* | ||
* @DataType( | ||
* id = "logger_entry", | ||
* label = @Translation("Logger entry"), | ||
* definition_class = "\Drupal\rules\TypedData\LoggerEntryDataDefinition" | ||
* ) | ||
*/ | ||
class LoggerEntry extends Map { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can look at examples for typed data in core: Language.php |
||
/** | ||
* The message's placeholders parser. | ||
* | ||
* @var \Drupal\Core\Logger\LogMessageParserInterface | ||
*/ | ||
protected $parser; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @todo: create a TypedData logger-entry object: https://www.drupal.org/node/2625238 | ||
*/ | ||
public function log($level, $message, array $context = array(), LogMessageParserInterface $parser) { | ||
$this->parser = $parser; | ||
|
||
// Remove any backtraces since they may contain an unserializable variable. | ||
unset($context['backtrace']); | ||
|
||
// Convert PSR3-style messages to SafeMarkup::format() style, so they can be | ||
// translated too in runtime. | ||
$message_placeholders = $this->parser->parseMessagePlaceholders($message, $context); | ||
|
||
$logger_entry = array( | ||
'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'], | ||
); | ||
|
||
$this->setValue($logger_entry); | ||
} | ||
|
||
// // Plain copy from \Drupal\rules\Logger\RulesLog | ||
// protected function createLoggerEntryFromContext($log) { | ||
// list($level, $message, $context) = $log; | ||
// | ||
// // Remove any backtraces since they may contain an unserializable variable. | ||
// unset($context['backtrace']); | ||
// | ||
// // Convert PSR3-style messages to SafeMarkup::format() style, so they can be | ||
// // translated too in runtime. | ||
// $message_placeholders = $this->parser->parseMessagePlaceholders($message, $context); | ||
// | ||
// $logger_entry = array( | ||
// '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'], | ||
// ); | ||
// | ||
// return $logger_entry; | ||
// } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\rules\Plugin\DataType\LoggerEntryDataDefinition. | ||
*/ | ||
|
||
namespace Drupal\rules\Plugin\DataType; | ||
|
||
use Drupal\Core\TypedData\MapDataDefinition; | ||
|
||
use Drupal\Core\Entity\EntityInterface; | ||
use Drupal\Core\Form\FormStateInterface; | ||
use Drupal\Core\TypedData\DataDefinitionInterface; | ||
use Drupal\Core\TypedData\Plugin\DataType\Map; | ||
use Drupal\Core\TypedData\TypedDataInterface; | ||
|
||
class LoggerEntryDataDefinition extends MapDataDefinition { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\rules\TypedData\LoggerEntryDataDefinition. | ||
*/ | ||
|
||
namespace Drupal\rules\TypedData; | ||
|
||
use Drupal\Core\TypedData\Plugin\DataType\Map; | ||
use Drupal\Core\TypedData\TypedData; | ||
use Drupal\Component\Utility\Random; | ||
use Drupal\Core\Field\FieldDefinitionInterface; | ||
use Drupal\Core\Field\FieldItemBase; | ||
use Drupal\Core\Field\FieldStorageDefinitionInterface; | ||
use Drupal\Core\Form\FormStateInterface; | ||
use Drupal\Core\TypedData\DataDefinition; | ||
use Drupal\Core\TypedData\MapDataDefinition; | ||
use Drupal\Core\Url; | ||
use Drupal\link\LinkItemInterface; | ||
|
||
|
||
/** | ||
* A typed data definition class for defining logger entries. | ||
*/ | ||
class LoggerEntryDataDefinition extends MapDataDefinition { | ||
|
||
/** | ||
* Definitions of the contained properties. | ||
* | ||
* @see self::getPropertyDefinitions() | ||
* | ||
* @var array | ||
*/ | ||
static $propertyDefinitions; | ||
|
||
/** | ||
* Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinitions(). | ||
*/ | ||
public function getPropertyDefinitions() { | ||
|
||
if (!isset(static::$propertyDefinitions)) { | ||
static::$propertyDefinitions['value'] = array( | ||
'type' => 'integer', | ||
'label' => t('Integer value'), | ||
'class' => '\Drupal\comment\CommentNewValue', | ||
'computed' => TRUE, | ||
); | ||
} | ||
return static::$propertyDefinitions; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need a config schema entry for the logger entry. It is not a config entity, it is just a typed data structure? Does the core Language data type for example have a config schema?