From 3c7686405dc2a217593266dc1cf6a453d7f6cf54 Mon Sep 17 00:00:00 2001 From: Konstantin Grachev Date: Mon, 13 Sep 2021 23:47:45 +0300 Subject: [PATCH] Dynamic log level on LookupException --- src/Exception/LookupException.php | 9 +++++++++ src/Lookup.php | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Exception/LookupException.php b/src/Exception/LookupException.php index 998dcfa..17085e8 100644 --- a/src/Exception/LookupException.php +++ b/src/Exception/LookupException.php @@ -4,6 +4,15 @@ declare(strict_types=1); namespace Nsq\Exception; +use Psr\Log\LogLevel; + final class LookupException extends NsqException { + public function level(): string + { + return match ($this->getMessage()) { + 'TOPIC_NOT_FOUND' => LogLevel::DEBUG, + default => LogLevel::WARNING, + }; + } } diff --git a/src/Lookup.php b/src/Lookup.php index 1d5019e..4bd6848 100644 --- a/src/Lookup.php +++ b/src/Lookup.php @@ -57,7 +57,7 @@ final class Lookup try { return Lookup\Response::fromJson($buffer); } catch (LookupException $e) { - $logger->warning($e->getMessage()); + $logger->log($e->level(), $uri.' '.$e->getMessage()); return null; }