Problem/Motivation
When an exception is logged to the dblog by \Drupal\Core\EventSubscriber\ExceptionLoggingSubscriber::onError()
or \Drupal\Core\Utility\Error::logException()
, there is no backtrace on the log event details page and it is very difficult to find the problem in code.
Steps to reproduce
Throw an exception from a controller and look at the message logged by dblog module.
Proposed resolution
Option A) When logging an exception, include the @backtrace_string placeholder in the log message - this key is already part of the "decoded" exception array. Note this placeholder has become something like a "standard" syntax for core log messages, so custom/contrib loggers can easily process or ignore it as desired. See for example dblog module which wraps the @backtrace_string with <pre class="backtrace"></pre>
tags.
Option B) [Chosen resolution] Do not add @backtrace_string to log messages; instead, because @backtrace_string is already part of the context array passed to loggers, dblog module can display the backtrace as a separate row at the bottom of the log details page. See #28
Remaining tasks
User interface changes
dblog module: PHP errors and some throwables already contained a backtrace in the log message - this is now expanded to an additional large set of throwables.
API changes
none
Data model changes
none