Skip to content

Commit

Permalink
Merge pull request #8108 from kenjis/feat-route-logging-in-exception
Browse files Browse the repository at this point in the history
feat: add Method/Route logging in exceptionHandler()
  • Loading branch information
kenjis authored Oct 29, 2023
2 parents f45040b + da93e63 commit a4127ca
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions system/Debug/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,21 @@ public function exceptionHandler(Throwable $exception)

[$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.
Expand Down

0 comments on commit a4127ca

Please sign in to comment.