diff --git a/src/Instrumentation/Laravel/src/Watchers/LogWatcher.php b/src/Instrumentation/Laravel/src/Watchers/LogWatcher.php index 7bacfa70a..e22a294af 100644 --- a/src/Instrumentation/Laravel/src/Watchers/LogWatcher.php +++ b/src/Instrumentation/Laravel/src/Watchers/LogWatcher.php @@ -29,15 +29,27 @@ public function register(Application $app): void $this->logger = $app['log']; } + public function shouldRecordLog(MessageLogged $log): bool + { + $underlyingLogger = $this->logger->getLogger(); + + /** @phan-suppress-next-line PhanUndeclaredMethod */ + if (method_exists($underlyingLogger, 'isHandling') + && method_exists($underlyingLogger, 'toMonologLevel') + && !$underlyingLogger->isHandling($underlyingLogger->toMonologLevel($log->level)) + ) { + return false; + } + + return true; + } + /** * Record a log. */ public function recordLog(MessageLogged $log): void { - $underlyingLogger = $this->logger->getLogger(); - - /** @phan-suppress-next-line PhanUndeclaredMethod */ - if (method_exists($underlyingLogger, 'isHandling') && !$underlyingLogger->isHandling($log->level)) { + if (!$this->shouldRecordLog($log)) { return; }