Problem/Motivation
Now the module creates custom log entries that are stored in a separate database table - it works well, but makes the logs a separate thing, detached from all other Drupal logs, and you have to store, manage, view, and clean up them separately.
This was done because the default Drupal logger was not extendable and didn't support storing custom fields and metadata. But the Logger module fixes this!
Using it, you can use the same standard PSR-3 Logger Interface to produce logs, but keep all the metadata, attached in the context, together with the log entry.
Having this, now you are able to store any fields just using a standard Drupal Logger service, and build reports with custom fields and filters by custom values directly in the Drupal admin panel using Views.
See these modules as an example of how to make this:
Proposed resolution
The proposal is to add an option to log using the standard Drupal Logger, providing all the custom metadata like payload, status, response body, etc, using the $context array.
Issue fork events_log_track-3552340
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
murzComment #3
smustgrave commentedWould definitely be a +1 for this. I more or less inherited this for a client project. For 5.0.x I'm trying to modernize it some so a feature like this would be welcome.
Comment #5
murz@smustgrave, thank you for the implementation!
My main concern there is that the logging is named as "Drupal database logging", but actually, the Logger module is not about the database, it just extends the standard Drupal logs to allow storing any free-form metadata and other custom fields.
Also, this approach should work with the Monolog logger too.
So, let's name the feature as something like "Drupal extended logs", with description like this:
What do you think about this?
And, by the way, I'm working now on decoupling the Logger DB module from the Logger, so it will work well independently, here is an issue with this feature: #3555898: Add support for Monolog and Drupal Core logger without the Logger module
Comment #6
murzAlso, if we implement this feature, we can simply get rid of (or, at start, just mark them as legacy) all other logging types (cli, syslog, stdout), because these log targets can be handled well by the Logger or Monolog modules, and the scope of the
events_log_trackmodule will be just prepare a log entry with all required data.And, together with this, get rid of other log handling code, at least the cron job, handling the
enable_log_deletionfeature, timespan_limit, batch_size, etc. Because the log clean-up and rotation should be the responsibility of the logger side, not this module.Comment #7
smustgrave commentedI want to give users options between events_log_track table and watchdog.
I would have to leave the syslog configuration just in case logger isn't installed? Unless we make it required
Comment #8
murzYes, let's not introduce the required dependency on the Logger module, just optional one.
And, to add "integration" with Logger (and with Monolog too), all you have to do - is just to add all the custom data to the "context" array of the Drupal default logger. So, instead of introducing a new logger, if you already have integration with the watchdog, maybe it's better to just add there an option "Add custom fields data to the log entries", with the description like this:
Comment #9
smustgrave commentedNot opposed to do some massive changes but still want to offer the 2 separate options. events_log_track table and watchdog
This module was very dated and been doing massive changes on the 5.0.x branch so if ever a time to make changes to the config now is it
Comment #10
murzI'm not about massive changes, but the opposite - trying to suggest minimizing the changes and the amount of the custom code. In the issue #3534876: Rework AI logging to use the default Drupal Logger with passing metadata in context, you can see how the integration with the Logger module was done for the "AI" module.
Comment #11
smustgrave commentedThanks for all the info! I'll have to sit down and review what changes to make.
Comment #12
murzAnd here #3535260: Provide AI usage reports in Drupal admin panel you can see how the custom log report page can be implemented, displaying the specific log entry fields as separate columns, with filitering by them.
Comment #13
murzAlso, take a look on the Request Logger module integration https://www.drupal.org/project/request_logger as a reference.
Comment #16
smustgrave commentedI absolutely did not mean to commit that.
Comment #17
smustgrave commentedWrapped a bit of the settings around this new config. Did ask Claude to cleanup the form (disclosure). As as deprecating other settings maybe follow ups?
Comment #18
smustgrave commentedI did move the syslog and stdlog logic all into the submodules. So if we do deprecate it will be much easier
Comment #19
smustgrave commentedrebased
Comment #20
murzSorry for the delay, reviewed now and even tested locally - it works well! But seems we have to make the settings form clearer, left comments in the MR about this.
Also, it would be good to track the installation of the syslog and stdout modules and show them in the settings form, to inform the user that the module starts logging to those targets too.
And, maybe add a note that instead of separate modules
syslogandlog_stdout, now users can just use the Logger module for all targets - db, syslog, stdout, and everything else.Comment #21
murzAlso, maybe plan a separate issue to create a submodule with the Logger DB dependency (to not introduce the dependency in the main module) that provides a Views page, which will represent logs stored by the Logger DB as a table like the current table on the page
/admin/reports/events-track, to be able to completely get rid of the custom storage?