Currently Drupal core does not provide a Typed Data Logger Entry.
@see: dblog and syslog

But the Rules logger implementation: System log entry is created needs that.

Comments

ndf created an issue. See original summary.

ndf’s picture

Title: Create Typed Data "Logger Entry" for "Logger Entry" event » Create Typed Data "Logger Entry" for "System log entry is created" event
Issue summary: View changes
Parent issue: » #2624848: Port "System:watchdog:system log entry is created" to D8
klausi’s picture

Issue tags: +Contributor
ndf’s picture

Assigned: Unassigned » ndf

Reading in on d8 TypedData: https://api.drupal.org/api/drupal/core!lib!Drupal!Core!TypedData!Plugin!...

The "map" data type represent a simple complex data type, e.g. for representing associative arrays. It can also serve as base class for any complex data type.

The current array

$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'],
    );

Moving to
https://github.com/fago/rules/pull/315

klausi’s picture

Status: Active » Needs work

Cool, left a couple of comments in the pull request.

ndf’s picture

I am still in a doubt.

There are 3 ways I've been investigation and I cannot make a decision about how logger_entry should be handled:

  • Extend \Drupal\Core\TypedData\Plugin\DataType\Map
  • Use config/schema/rules.schema.yml
  • Make it an entity with all the bells and whistles

Notes:

approach new DataType

Extend \Drupal\Core\TypedData\Plugin\DataType\Map
Doing class LoggerEntry extends Map with annotation definition_class = "\Drupal\rules\TypedData\LoggerEntryDataDefinition" initiating new LoggerEntry() gives a runtime-error that the definition must be passed to the LoggerEntry __constructor.
This is probably just wrongly implemented by me.
Have been looking through a lot of core-examples of extends Map() and other TypedDate implementations. But I could not find one or more with this typical 'associative array with a couple of fixed keys and expected values' setup like logger_entry has.

Via .yml

config/schema/rules.schema.yml
This method seems to be used for config-entities only. The definition (via .yml) looks very clear and simple though.
see below for the .yml I made up for now.

Make it an entity

Make it an entity with all the bells and whistles
Seems a fine approach, all though I could imagine it might have performance impact.
I am not sure if this means that all logger_entries now should be saved to the db or not.
But it could be an attractive approach because of a lot of integrations we get for free.

Example *.schema.yml for logger entry

rules.data_type.logger_entry.definition:
  type: mapping
  label: 'Logger Entry'
  mapping:
    uid:
      type: user
      label: 'User'
    channel:
      type: string
      label: 'Channel'
    message:
      type: string
      label: 'Message'
    variables:
      type: string
      label: 'Message placeholders'
    severity:
      type: string
      label: 'Level'
    link:
      type: link
      label: 'Link'
    location:
      type: url
      label: 'Request URI'
    referer:
      type: string
      label: 'Referer'
    hostname:
      type: string
      label: 'IP'
    timestamp:
      type: data
      label: 'Timestamp'
klausi’s picture

Left a couple of comments in the pull request.

Yes, you will need a data definition class for the logger entry data type. It should not be an entity, since such a log entry cannot be saved. It is just data. The config schema shoould also not be necessary.

amateescu’s picture

Note that the current Rules logger has a small bug: #2803823: Rules' logger needs to take care of its internal properties on serialization so we'll need to port that fix to this issue as well.

TR’s picture

@ndf - this is still assigned to you. Are you going to work on it?

ndf’s picture

Assigned: ndf » Unassigned

@TR nope, I unassigned myself

TR’s picture

Added #1349882: Action: Create a watchdog entry as a related issue - that issue is for D7, but both that and this require exposing the watchdog log entry data structure to Rules. The data structure produced by the event should be the same as the data structure produced by the action.

TR’s picture

Title: Create Typed Data "Logger Entry" for "System log entry is created" event » Create Typed Data "Logger Entry" type
Project: Rules » Typed Data API enhancements
Version: 8.x-3.x-dev » 8.x-1.x-dev
Component: Rules Core » Miscellaneous
Issue summary: View changes

Moving this to the Typed Data API module, as that is where I think we should be putting generally-useful data type definitions.

TR’s picture

Version: 8.x-1.x-dev » 2.0.x-dev