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
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3392020-jsonlog-exception-2.patch | 4.06 KB | smokris |
Comments
Comment #2
smokrisPatch attached.
Comment #3
lorenzs commented