summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxjm2016-08-02 17:05:52 (GMT)
committerxjm2016-08-02 17:05:52 (GMT)
commitdd1c1ce6d594a62701720721d6b7e97ff2bdd176 (patch)
tree1c30c99e9bf5ce0ef4dd6b1c395ce7735a61c312
parentbc834169f0ffcd4a98038f957ff2d5c3392cf544 (diff)
Issue #2638140 by alexpott, dawehner, cilefen, xjm, Fabianx, Xano, catch: Error logging should log a backtrace consistently
-rw-r--r--core/includes/errors.inc13
-rw-r--r--core/lib/Drupal/Core/Utility/Error.php2
-rw-r--r--core/modules/system/src/Tests/System/UncaughtExceptionTest.php2
3 files changed, 9 insertions, 8 deletions
diff --git a/core/includes/errors.inc b/core/includes/errors.inc
index b96b828..e3ad1c8 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 aca31fa..6105a59 100644
--- a/core/lib/Drupal/Core/Utility/Error.php
+++ b/core/lib/Drupal/Core/Utility/Error.php
@@ -71,7 +71,7 @@ class Error {
'%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 0cc6862..c155781 100644
--- a/core/modules/system/src/Tests/System/UncaughtExceptionTest.php
+++ b/core/modules/system/src/Tests/System/UncaughtExceptionTest.php
@@ -253,7 +253,7 @@ class UncaughtExceptionTest extends WebTestBase {
// 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';