diff --git a/src/Watchers/LogWatcher.php b/src/Watchers/LogWatcher.php index f887da8..3c9537f 100644 --- a/src/Watchers/LogWatcher.php +++ b/src/Watchers/LogWatcher.php @@ -11,11 +11,28 @@ class LogWatcher extends Watcher { + private const DEBUG = 1; + private const INFO = 2; + private const NOTICE = 3; + private const WARNING = 4; + private const ERROR = 5; + private const CRITICAL = 6; + private const ALERT = 7; + private const EMERGENCY = 8; + + private int $minLogLevel; + /** @psalm-suppress UndefinedInterfaceMethod */ public function register(Application $app): void { /** @phan-suppress-next-line PhanTypeArraySuspicious */ $app['events']->listen(MessageLogged::class, [$this, 'recordLog']); + + $this->minLogLevel = self::INFO; + $levelStr = strtoupper(env("OTEL_PHP_LOG_LEVEL", "INFO")); + if (defined(self::class.'::'.$levelStr)) { + $this->minLogLevel = constant(self::class . '::' . $levelStr); + } } /** @@ -23,6 +40,13 @@ public function register(Application $app): void */ public function recordLog(MessageLogged $log): void { + if ( + defined(self::class.'::'.strtoupper($log->level)) && + constant(self::class . '::' . strtoupper($log->level)) < $this->minLogLevel + ) { + return; + } + $attributes = [ 'level' => $log->level, ];