Problem: Drupal only logs the current line for a PHP error or an exception. I want a backtrace to actually know where the error came from.

Proposed solution: log a lightweight backtrace with print_r() as additional watchdog() variable.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

klausi created an issue. See original summary.

klausi’s picture

Status: Active » Needs review
FileSize
2.59 KB

Patch.

Alan D.’s picture

Status: Needs review » Closed (duplicate)
Related issues: +#1158322: Add backtrace to all errors

As the author wrote, the one being worked on core is too large and probably too slow on the uptake.

klausi’s picture

Status: Closed (duplicate) » Needs review

Let's keep this open as an alternative to the other issue.

david_garcia’s picture

In D8 it is perfectly possible to deal with this from contrib without hacking core. That might be a better place for this to move on...

cilefen’s picture

gapple’s picture

An updated patch to keep up with a change to _drupal_log_error()

caschbre’s picture

Here is an updated patch that uses several variables to optionally provide the "heavy" or "light" version. The previous patch calls debug_backtrace as the "heavy" version and then unsets array elements to make it light. The new patch uses the debug_backtrace $options parameter to do this which makes execution faster. This also gives the developer an option to output the object/args elements in the backtrace by setting a variable.

So instead of:

$backtrace = debug_backtrace();

// Remove arguments/objects from the backtrace to make it lightweight.
foreach ($backtrace as $key => $value) {
  unset($backtrace[$key]['object']);
  unset($backtrace[$key]['args']);
}

We have:

$backtrace_options = variable_get('drupal_error_backtrace_options', DEBUG_BACKTRACE_IGNORE_ARGS);
$backtrace_limit = variable_get('drupal_error_backtrace_limit', 0);
$backtrace = debug_backtrace($backtrace_options, $backtrace_limit);
dalin’s picture

Status: Needs review » Closed (duplicate)

Dupe of #1158322: Add backtrace to all errors which has had much more activity on it.