Support logging data from exceptions

Created on 5 October 2023, about 1 year ago
Updated 13 October 2023, about 1 year ago

Problem/Motivation

PSR-3 specifies that exception objects should be stored in the context's exception key. Currently jsonlog ignores this key, so the exception data is lost, instead of being included in JSON log messages.

Steps to reproduce

This command…

drush eval '\Drupal::logger("test_logger")->error("test message", ["exception" => new \Exception("test exception")]);'

…outputs this JSON log…

{"@timestamp":"2023-10-05T17:19:09.161Z","@version":1,"message":"test message","message_id":"d10test651ef00d2741c4.46456678","site_id":"d10test","canonical":"","method":"GET","tags":null,"type":"drupal","subtype":"test_logger","severity":"Error","request_uri":"https:\/\/d10test.ddev.site\/","referer":"","uid":0,"username":"","client_ip":"127.0.0.1","link":null,"code":0,"trunc":""}

…which lacks the "test exception" string and other info from the \Exception object.

Proposed resolution

Include the exception data in the JSON log message as a new "exception" key.

Remaining tasks

Review patch.

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Feature request
Status

Needs review

Version

4.0

Component

Code

Created by

🇺🇸United States smokris Athens, Ohio, USA

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

Comments & Activities

Production build 0.71.5 2024