Merge pull request #8108 from kenjis/feat-route-logging-in-exception

feat: add Method/Route logging in exceptionHandler()
This commit is contained in:
kenjis 2023-10-29 09:01:40 +09:00 committed by GitHub
commit a4127ca3d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -125,16 +125,21 @@ class Exceptions
[$statusCode, $exitCode] = $this->determineCodes($exception);
$this->request = Services::request();
if ($this->config->log === true && ! in_array($statusCode, $this->config->ignoreCodes, true)) {
log_message('critical', "{message}\nin {exFile} on line {exLine}.\n{trace}", [
'message' => $exception->getMessage(),
'exFile' => clean_path($exception->getFile()), // {file} refers to THIS file
'exLine' => $exception->getLine(), // {line} refers to THIS line
'trace' => self::renderBacktrace($exception->getTrace()),
$uri = $this->request->getPath() === '' ? '/' : $this->request->getPath();
$routeInfo = '[Method: ' . strtoupper($this->request->getMethod()) . ', Route: ' . $uri . ']';
log_message('critical', "{message}\n{routeInfo}\nin {exFile} on line {exLine}.\n{trace}", [
'message' => $exception->getMessage(),
'routeInfo' => $routeInfo,
'exFile' => clean_path($exception->getFile()), // {file} refers to THIS file
'exLine' => $exception->getLine(), // {line} refers to THIS line
'trace' => self::renderBacktrace($exception->getTrace()),
]);
}
$this->request = Services::request();
$this->response = Services::response();
// Get the first exception.