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

CommentFileSizeAuthor
#2 3392020-jsonlog-exception-2.patch4.06 KBsmokris

Comments

smokris created an issue. See original summary.

smokris’s picture

Assigned: smokris » Unassigned
Status: Active » Needs review
StatusFileSize
new4.06 KB

Patch attached.

lorenzs’s picture

Version: 3.x-dev » 4.x-dev