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.

Command icon 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

murz created an issue. See original summary.

murz’s picture

Issue summary: View changes
smustgrave’s picture

Version: 4.0.x-dev » 5.0.x-dev

Would 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.

murz’s picture

@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:

Enables logging events to the standard Drupal logger with passing the event data to the context. This feature requires extending the default Drupal Logger by one of these modules: Logger, Monolog, Logger DB.

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

murz’s picture

Also, 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_track module 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_deletion feature, timespan_limit, batch_size, etc. Because the log clean-up and rotation should be the responsibility of the logger side, not this module.

smustgrave’s picture

I 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

murz’s picture

Yes, 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:

Enables passing the event data to the context of the log entry. This feature requires extending the default Drupal Logger by one of these modules: Logger, Monolog, Logger DB.

smustgrave’s picture

Not 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

murz’s picture

I'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.

smustgrave’s picture

Thanks for all the info! I'll have to sit down and review what changes to make.

murz’s picture

And 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.

murz’s picture

Also, take a look on the Request Logger module integration https://www.drupal.org/project/request_logger as a reference.

  • smustgrave committed 2fe0da5b on 5.0.x
    feat: #3552340 Implement logging to the Drupal Logger with submitting...

  • smustgrave committed 868b718a on 5.0.x
    Revert "feat: #3552340 Implement logging to the Drupal Logger with...
smustgrave’s picture

I absolutely did not mean to commit that.

smustgrave’s picture

Status: Active » Needs review

Wrapped 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?

smustgrave’s picture

I did move the syslog and stdlog logic all into the submodules. So if we do deprecate it will be much easier

smustgrave’s picture

rebased

murz’s picture

Status: Needs review » Active

Sorry 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 syslog and log_stdout, now users can just use the Logger module for all targets - db, syslog, stdout, and everything else.

murz’s picture

Also, 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?