Skip to content

Commit 886aa89

Browse files
committed
feat: log exception classname and all previous exceptions
1 parent 181b93f commit 886aa89

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

system/Debug/Exceptions.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,26 @@ public function exceptionHandler(Throwable $exception)
125125
[$statusCode, $exitCode] = $this->determineCodes($exception);
126126

127127
if ($this->config->log === true && ! in_array($statusCode, $this->config->ignoreCodes, true)) {
128-
log_message('critical', "{message}\nin {exFile} on line {exLine}.\n{trace}", [
128+
log_message('critical', get_class($exception) . ": {message}\nin {exFile} on line {exLine}.\n{trace}", [
129129
'message' => $exception->getMessage(),
130130
'exFile' => clean_path($exception->getFile()), // {file} refers to THIS file
131131
'exLine' => $exception->getLine(), // {line} refers to THIS line
132132
'trace' => self::renderBacktrace($exception->getTrace()),
133133
]);
134+
135+
// Get the first exception.
136+
$last = $exception;
137+
138+
while ($prevException = $last->getPrevious()) {
139+
$last = $prevException;
140+
141+
log_message('critical', '[Caused by] ' . get_class($prevException) . ": {message}\nin {exFile} on line {exLine}.\n{trace}", [
142+
'message' => $prevException->getMessage(),
143+
'exFile' => clean_path($prevException->getFile()), // {file} refers to THIS file
144+
'exLine' => $prevException->getLine(), // {line} refers to THIS line
145+
'trace' => self::renderBacktrace($prevException->getTrace()),
146+
]);
147+
}
134148
}
135149

136150
$this->request = Services::request();

0 commit comments

Comments
 (0)