diff --git a/src/Illuminate/Foundation/Exceptions/Handler.php b/src/Illuminate/Foundation/Exceptions/Handler.php index 227b9e2319b0..dc3cf85f5b86 100644 --- a/src/Illuminate/Foundation/Exceptions/Handler.php +++ b/src/Illuminate/Foundation/Exceptions/Handler.php @@ -265,15 +265,15 @@ public function report(Throwable $e) $this->levels, fn ($level, $type) => $e instanceof $type, LogLevel::ERROR ); - $logger->log( - $level, - $e->getMessage(), - array_merge( - $this->exceptionContext($e), - $this->context(), - ['exception' => $e] - ) + $context = array_merge( + $this->exceptionContext($e), + $this->context(), + ['exception' => $e] ); + + method_exists($logger, $level) + ? $logger->{$level}($e->getMessage(), $context) + : $logger->log($level, $e->getMessage(), $context); } /** diff --git a/tests/Foundation/FoundationExceptionsHandlerTest.php b/tests/Foundation/FoundationExceptionsHandlerTest.php index b5ff8db4cb0c..51d8a71027ab 100644 --- a/tests/Foundation/FoundationExceptionsHandlerTest.php +++ b/tests/Foundation/FoundationExceptionsHandlerTest.php @@ -74,7 +74,7 @@ public function testHandlerReportsExceptionAsContext() { $logger = m::mock(LoggerInterface::class); $this->container->instance(LoggerInterface::class, $logger); - $logger->shouldReceive('log')->withArgs([LogLevel::ERROR, 'Exception message', m::hasKey('exception')])->once(); + $logger->shouldReceive('error')->withArgs(['Exception message', m::hasKey('exception')])->once(); $this->handler->report(new RuntimeException('Exception message')); } @@ -83,7 +83,7 @@ public function testHandlerCallsContextMethodIfPresent() { $logger = m::mock(LoggerInterface::class); $this->container->instance(LoggerInterface::class, $logger); - $logger->shouldReceive('log')->withArgs([LogLevel::ERROR, 'Exception message', m::subset(['foo' => 'bar'])])->once(); + $logger->shouldReceive('error')->withArgs(['Exception message', m::subset(['foo' => 'bar'])])->once(); $this->handler->report(new ContextProvidingException('Exception message')); } @@ -92,7 +92,7 @@ public function testHandlerReportsExceptionWhenUnReportable() { $logger = m::mock(LoggerInterface::class); $this->container->instance(LoggerInterface::class, $logger); - $logger->shouldReceive('log')->withArgs([LogLevel::ERROR, 'Exception message', m::hasKey('exception')])->once(); + $logger->shouldReceive('error')->withArgs(['Exception message', m::hasKey('exception')])->once(); $this->handler->report(new UnReportableException('Exception message')); } @@ -101,16 +101,17 @@ public function testHandlerReportsExceptionWithCustomLogLevel() { $logger = m::mock(LoggerInterface::class); $this->container->instance(LoggerInterface::class, $logger); - $logger->shouldReceive('log')->withArgs([LogLevel::CRITICAL, 'Critical message', m::hasKey('exception')])->once(); - $logger->shouldReceive('log')->withArgs([LogLevel::ERROR, 'Error message', m::hasKey('exception')])->once(); - $logger->shouldReceive('log')->withArgs([LogLevel::WARNING, 'Warning message', m::hasKey('exception')])->once(); + + $logger->shouldReceive('critical')->withArgs(['Critical message', m::hasKey('exception')])->once(); + $logger->shouldReceive('error')->withArgs(['Error message', m::hasKey('exception')])->once(); + $logger->shouldReceive('log')->withArgs(['custom', 'Custom message', m::hasKey('exception')])->once(); $this->handler->level(InvalidArgumentException::class, LogLevel::CRITICAL); - $this->handler->level(OutOfRangeException::class, LogLevel::WARNING); + $this->handler->level(OutOfRangeException::class, 'custom'); $this->handler->report(new InvalidArgumentException('Critical message')); $this->handler->report(new RuntimeException('Error message')); - $this->handler->report(new OutOfRangeException('Warning message')); + $this->handler->report(new OutOfRangeException('Custom message')); } public function testHandlerIgnoresNotReportableExceptions()