diff --git a/includes/errors.inc b/includes/errors.inc index 7393148..1ae84bb 100644 --- a/includes/errors.inc +++ b/includes/errors.inc @@ -62,8 +62,7 @@ function _drupal_error_handler_real($error_level, $message, $filename, $line, $c require_once DRUPAL_ROOT . '/includes/common.inc'; } - // We treat recoverable errors as fatal. - _drupal_log_error(array( + $error_details = array( '%type' => isset($types[$error_level]) ? $severity_msg : 'Unknown error', // The standard PHP error handler considers that the error messages // are HTML. We mimick this behavior here. @@ -72,7 +71,14 @@ function _drupal_error_handler_real($error_level, $message, $filename, $line, $c '%file' => $caller['file'], '%line' => $caller['line'], 'severity_level' => $severity_level, - ), $error_level == E_RECOVERABLE_ERROR); + ); + + if (variable_get('enable_backtrace', TRUE)) { + $error_details['@backtrace_string'] = (new \Exception())->getTraceAsString(); + } + + // We treat recoverable errors as fatal. + _drupal_log_error($error_details, $error_level == E_RECOVERABLE_ERROR); } } @@ -111,7 +117,7 @@ function _drupal_decode_exception($exception) { } $caller = _drupal_get_last_caller($backtrace); - return array( + $error_details = array( '%type' => get_class($exception), // The standard PHP exception handler considers that the exception message // is plain-text. We mimick this behavior here. @@ -121,6 +127,12 @@ function _drupal_decode_exception($exception) { '%line' => $caller['line'], 'severity_level' => WATCHDOG_ERROR, ); + + if (variable_get('enable_backtrace', TRUE)) { + $error_details['@backtrace_string'] = (new \Exception())->getTraceAsString(); + } + + return $error_details; } /** @@ -211,6 +223,13 @@ function _drupal_log_error($error, $fatal = FALSE) { } if ($fatal) { + + if (array_key_exists('@backtrace_string', $error)) { + error_log(sprintf('%s: %s in %s on line %d %s', $error['%type'], $error['!message'], $error['%file'], $error['%line'], $error['@backtrace_string'])); + } + else { + error_log(sprintf('%s: %s in %s on line %d', $error['%type'], $error['!message'], $error['%file'], $error['%line'])); + } drupal_add_http_header('Status', '500 Service unavailable (with message)'); }