diff --git a/core/includes/errors.inc b/core/includes/errors.inc index b96b8281dd5c62b3e8ab780e8b4c09229e3e84c2..e3ad1c89e1743454453b9ebc416b33649f1e6a2e 100644 --- a/core/includes/errors.inc +++ b/core/includes/errors.inc @@ -80,6 +80,7 @@ function _drupal_error_handler_real($error_level, $message, $filename, $line, $c '%line' => $caller['line'], 'severity_level' => $severity_level, 'backtrace' => $backtrace, + '@backtrace_string' => (new \Exception())->getTraceAsString(), ), $recoverable || $to_string); } } @@ -116,9 +117,9 @@ function error_displayable($error = NULL) { * * @param $error * An array with the following keys: %type, @message, %function, %file, - * %line, severity_level, and backtrace. All the parameters are plain-text, - * with the exception of @message, which needs to be an HTML string, and - * backtrace, which is a standard PHP backtrace. + * %line, @backtrace_string, severity_level, and backtrace. All the parameters + * are plain-text, with the exception of @message, which needs to be an HTML + * string, and backtrace, which is a standard PHP backtrace. * @param bool $fatal * TRUE for: * - An exception is thrown and not caught by something else. @@ -163,18 +164,18 @@ function _drupal_log_error($error, $fatal = FALSE) { // installer. if (\Drupal::hasService('logger.factory')) { try { - \Drupal::logger('php')->log($error['severity_level'], '%type: @message in %function (line %line of %file).', $error); + \Drupal::logger('php')->log($error['severity_level'], '%type: @message in %function (line %line of %file) @backtrace_string.', $error); } catch (\Exception $e) { // We can't log, for example because the database connection is not // available. At least try to log to PHP error log. - error_log(strtr('Failed to log error: %type: @message in %function (line %line of %file).', $error)); + error_log(strtr('Failed to log error: %type: @message in %function (line %line of %file). @backtrace_string', $error)); } } // Log fatal errors, so developers can find and debug them. if ($fatal) { - error_log(sprintf('%s: %s in %s on line %d', $error['%type'], $error['@message'], $error['%file'], $error['%line'])); + error_log(sprintf('%s: %s in %s on line %d %s', $error['%type'], $error['@message'], $error['%file'], $error['%line'], $error['@backtrace_string'])); } if (PHP_SAPI === 'cli') { diff --git a/core/lib/Drupal/Core/Utility/Error.php b/core/lib/Drupal/Core/Utility/Error.php index aca31fae837ffec6c238c4189d5286b8e990d739..6105a59021cbc06388b8cf7e6a382ec95351bddc 100644 --- a/core/lib/Drupal/Core/Utility/Error.php +++ b/core/lib/Drupal/Core/Utility/Error.php @@ -71,7 +71,7 @@ public static function decodeException($exception) { '%line' => $caller['line'], 'severity_level' => static::ERROR, 'backtrace' => $backtrace, - 'backtrace_string' => $exception->getTraceAsString(), + '@backtrace_string' => $exception->getTraceAsString(), ); } diff --git a/core/modules/system/src/Tests/System/UncaughtExceptionTest.php b/core/modules/system/src/Tests/System/UncaughtExceptionTest.php index 0cc68627a5b4fa1981268fefa3ffba8c38d2a90c..c155781d518d529a177fda62121d8689f0278c54 100644 --- a/core/modules/system/src/Tests/System/UncaughtExceptionTest.php +++ b/core/modules/system/src/Tests/System/UncaughtExceptionTest.php @@ -253,7 +253,7 @@ public function testLoggerException() { // Find fatal error logged to the simpletest error.log $errors = file(\Drupal::root() . '/' . $this->siteDirectory . '/error.log'); - $this->assertIdentical(count($errors), 2, 'The error + the error that the logging service is broken has been written to the error log.'); + $this->assertIdentical(count($errors), 8, 'The error + the error that the logging service is broken has been written to the error log.'); $this->assertTrue(strpos($errors[0], 'Failed to log error') !== FALSE, 'The error handling logs when an error could not be logged to the logger.'); $expected_path = \Drupal::root() . '/core/modules/system/tests/modules/error_service_test/src/MonkeysInTheControlRoom.php';