Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to be able to override the exception context format #44895

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/Illuminate/Foundation/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,7 @@ public function report(Throwable $e)
$this->levels, fn ($level, $type) => $e instanceof $type, LogLevel::ERROR
);

$context = array_merge(
$this->exceptionContext($e),
$this->context(),
['exception' => $e]
);
$context = $this->buildExceptionContext($e);

method_exists($logger, $level)
? $logger->{$level}($e->getMessage(), $context)
Expand Down Expand Up @@ -303,6 +299,21 @@ protected function shouldntReport(Throwable $e)
return ! is_null(Arr::first($dontReport, fn ($type) => $e instanceof $type));
}

/**
* Create the context array for logging the given exception.
*
* @param \Throwable $e
* @return array
*/
protected function buildExceptionContext(Throwable $e)
{
return array_merge(
$this->exceptionContext($e),
$this->context(),
['exception' => $e]
);
}

/**
* Get the default exception context variables for logging.
*
Expand Down