Skip to content

Commit a4127ca

Browse files
authored
Merge pull request #8108 from kenjis/feat-route-logging-in-exception
feat: add Method/Route logging in exceptionHandler()
2 parents f45040b + da93e63 commit a4127ca

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

system/Debug/Exceptions.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,21 @@ public function exceptionHandler(Throwable $exception)
125125

126126
[$statusCode, $exitCode] = $this->determineCodes($exception);
127127

128+
$this->request = Services::request();
129+
128130
if ($this->config->log === true && ! in_array($statusCode, $this->config->ignoreCodes, true)) {
129-
log_message('critical', "{message}\nin {exFile} on line {exLine}.\n{trace}", [
130-
'message' => $exception->getMessage(),
131-
'exFile' => clean_path($exception->getFile()), // {file} refers to THIS file
132-
'exLine' => $exception->getLine(), // {line} refers to THIS line
133-
'trace' => self::renderBacktrace($exception->getTrace()),
131+
$uri = $this->request->getPath() === '' ? '/' : $this->request->getPath();
132+
$routeInfo = '[Method: ' . strtoupper($this->request->getMethod()) . ', Route: ' . $uri . ']';
133+
134+
log_message('critical', "{message}\n{routeInfo}\nin {exFile} on line {exLine}.\n{trace}", [
135+
'message' => $exception->getMessage(),
136+
'routeInfo' => $routeInfo,
137+
'exFile' => clean_path($exception->getFile()), // {file} refers to THIS file
138+
'exLine' => $exception->getLine(), // {line} refers to THIS line
139+
'trace' => self::renderBacktrace($exception->getTrace()),
134140
]);
135141
}
136142

137-
$this->request = Services::request();
138143
$this->response = Services::response();
139144

140145
// Get the first exception.

0 commit comments

Comments
 (0)