Rework AI Logging to use the standard PSR Logger interface with passing metadata in context

Created on 9 July 2025, 6 days ago

Problem/Motivation

The current AI Logging submodule implementation invented a custom logging solution, with a custom log entity type that uses separate fields to store data, and a Views UI to display it.

Keeping the custom log implementation is not good for several reasons:

  • Performance: Storing logs in SQL is good for quick start and local testing, but not good for performance.
  • Support: If we keep the current solution, we have to support and manage a lot of logging and displaying logs related code.
  • Custom logging: A lot of sites use custom logging to not overload the database with log records and not decrease the logging performance. So they use logging to syslog, files, stdout, custom filtering, aggregating, etc. And covering all these in the scope of the "ai_logging" module will be quite a challenge.

Proposed resolution

I believe that we can just use the standard PSR Logger interface to pass all the metadata to the log entry, and handle storing the metadata on the PSR Logger implementation side.

So, from the "ai_logging" module site (or maybe even do not create a separate module for this?), we just create a default Drupal log entry, which displays the most useful log data in the "message" text, that can be viewed and managed via any standard way in Drupal. And just pass all the additional metadata as context, which can be processed and stored in different ways.

A good candidate for storing custom data together with the PSR log entry is the Extended Logger module that allows storing any metadata together with the log record. But this module is not required, so we can not introduce a hard dependency on it, but just recommend it as an option, if someone wants to get more detailed logs. And for most cases, the default Drupal Watchdog should be enough.

Remaining tasks

  • Decide on the solution and finalize it.
Feature request
Status

Active

Version

1.1

Component

AI Logging

Created by

🇦🇲Armenia murz Yerevan, Armenia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @murz
  • 🇦🇲Armenia murz Yerevan, Armenia
  • 🇦🇲Armenia murz Yerevan, Armenia

    I extended the log displaying styles to allow display of AI Logging logs exactly like in the current module, here are the screenshots to compare:
    AI Logging Logs page:

    Extended Logger logs page:

    This, for now, requires a patch from #3534928: [DB] Allow customizing the output of JSON fields on the logs page but looks promising. So, we can just submit logs to the Drupal Logger, then clone and customize a Views page, provided by Extended Logger, to display the metadata as fields in nthe eeded format.

  • 🇦🇲Armenia murz Yerevan, Armenia

    The logs are rendered from the same source and the output is controlled by the Views field settings with no code changes, so here are two examples of how we can customize and beautify them:
    - Just beautify the response object:

    - Extract the response data into two separate fields (Response, Token usage):

Production build 0.71.5 2024