From fbd459e448f5ed3cc684326f8aeaeabba6215184 Mon Sep 17 00:00:00 2001 From: Takayasu Oyama Date: Fri, 6 Sep 2024 09:48:33 +0900 Subject: [PATCH 1/3] [11.x] Add Exceptions\Handler::mapLogLevel so the logic can be easily overridden --- .../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..d0e38df6104a 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); @@ -1056,4 +1054,17 @@ protected function newLogger() { return $this->container->make(LoggerInterface::class); } + + /** + * 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 + ); + } } From fff3cdfabed4e84913df47138688c2dd476dab91 Mon Sep 17 00:00:00 2001 From: Takayasu Oyama Date: Fri, 6 Sep 2024 09:57:32 +0900 Subject: [PATCH 2/3] formatting --- src/Illuminate/Foundation/Exceptions/Handler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Exceptions/Handler.php b/src/Illuminate/Foundation/Exceptions/Handler.php index d0e38df6104a..583fd94e7d9e 100644 --- a/src/Illuminate/Foundation/Exceptions/Handler.php +++ b/src/Illuminate/Foundation/Exceptions/Handler.php @@ -1058,7 +1058,7 @@ protected function newLogger() /** * Map the exception to a log level. * - * @param Throwable $e + * @param Throwable $e * @return \Psr\Log\LogLevel::* */ protected function mapLogLevel(Throwable $e) From ea6008a13262f49c4b15329bdf1680a94304266b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 6 Sep 2024 08:41:25 -0500 Subject: [PATCH 3/3] formatting --- .../Foundation/Exceptions/Handler.php | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Illuminate/Foundation/Exceptions/Handler.php b/src/Illuminate/Foundation/Exceptions/Handler.php index 583fd94e7d9e..4effa0c9990d 100644 --- a/src/Illuminate/Foundation/Exceptions/Handler.php +++ b/src/Illuminate/Foundation/Exceptions/Handler.php @@ -1045,20 +1045,10 @@ protected function isHttpException(Throwable $e) return $e instanceof HttpExceptionInterface; } - /** - * Create a new logger instance. - * - * @return \Psr\Log\LoggerInterface - */ - protected function newLogger() - { - return $this->container->make(LoggerInterface::class); - } - /** * Map the exception to a log level. * - * @param Throwable $e + * @param \Throwable $e * @return \Psr\Log\LogLevel::* */ protected function mapLogLevel(Throwable $e) @@ -1067,4 +1057,14 @@ protected function mapLogLevel(Throwable $e) $this->levels, fn ($level, $type) => $e instanceof $type, LogLevel::ERROR ); } + + /** + * Create a new logger instance. + * + * @return \Psr\Log\LoggerInterface + */ + protected function newLogger() + { + return $this->container->make(LoggerInterface::class); + } }