From bb670ae486579b6121dc21f3dee35a1b50825746 Mon Sep 17 00:00:00 2001 From: Takayasu Oyama Date: Fri, 6 Sep 2024 22:41:41 +0900 Subject: [PATCH] [11.x] Add Exceptions\Handler::mapLogLevel(...) so the logic can be easily overridden (#52666) * [11.x] Add Exceptions\Handler::mapLogLevel so the logic can be easily overridden * formatting * formatting --------- Co-authored-by: Taylor Otwell --- .../Foundation/Exceptions/Handler.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Foundation/Exceptions/Handler.php b/src/Illuminate/Foundation/Exceptions/Handler.php index 6da808a4f352..4effa0c9990d 100644 --- a/src/Illuminate/Foundation/Exceptions/Handler.php +++ b/src/Illuminate/Foundation/Exceptions/Handler.php @@ -368,9 +368,7 @@ protected function reportThrowable(Throwable $e): void throw $e; } - $level = Arr::first( - $this->levels, fn ($level, $type) => $e instanceof $type, LogLevel::ERROR - ); + $level = $this->mapLogLevel($e); $context = $this->buildExceptionContext($e); @@ -1047,6 +1045,19 @@ protected function isHttpException(Throwable $e) return $e instanceof HttpExceptionInterface; } + /** + * Map the exception to a log level. + * + * @param \Throwable $e + * @return \Psr\Log\LogLevel::* + */ + protected function mapLogLevel(Throwable $e) + { + return Arr::first( + $this->levels, fn ($level, $type) => $e instanceof $type, LogLevel::ERROR + ); + } + /** * Create a new logger instance. *