From 37f3ec2688639f2bfe6182eba44ce47710c660c9 Mon Sep 17 00:00:00 2001 From: Michel van de Wetering Date: Thu, 18 Apr 2024 19:57:37 +0200 Subject: [PATCH 1/4] Log host --- aiohuesyncbox/huesyncbox.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aiohuesyncbox/huesyncbox.py b/aiohuesyncbox/huesyncbox.py index c27dff5..913b604 100644 --- a/aiohuesyncbox/huesyncbox.py +++ b/aiohuesyncbox/huesyncbox.py @@ -50,6 +50,8 @@ async def resolve(self, host, port=0, family=socket.AF_INET): for host in hosts: host["hostname"] = self._common_name + logger.debug("Resolved hosts: %s", hosts) + return hosts From 6b372e8840252f786d35f7b6076a45c926b7d6cc Mon Sep 17 00:00:00 2001 From: Michel van de Wetering Date: Thu, 18 Apr 2024 20:24:55 +0200 Subject: [PATCH 2/4] Log all handled exceptions --- aiohuesyncbox/huesyncbox.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aiohuesyncbox/huesyncbox.py b/aiohuesyncbox/huesyncbox.py index 913b604..a57ec76 100644 --- a/aiohuesyncbox/huesyncbox.py +++ b/aiohuesyncbox/huesyncbox.py @@ -232,10 +232,12 @@ async def request( ) return data except aiohttp.ClientError as err: + logger.debug(err, exc_info=True) raise RequestError( f"Error requesting data from {self._host}" ) from err except asyncio.TimeoutError as err: + logger.debug(err, exc_info=True) raise RequestError( f"Timeout requesting data from {self._host}" ) from err From 44b4da1ffeb92f1464e8dd4f3bfbc21efc27d572 Mon Sep 17 00:00:00 2001 From: Michel van de Wetering Date: Thu, 18 Apr 2024 20:25:16 +0200 Subject: [PATCH 3/4] Log API errors --- aiohuesyncbox/errors.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/aiohuesyncbox/errors.py b/aiohuesyncbox/errors.py index f97766f..d71a9bf 100644 --- a/aiohuesyncbox/errors.py +++ b/aiohuesyncbox/errors.py @@ -1,5 +1,9 @@ """Aiohuesyncbox errors.""" +import logging + +logger = logging.getLogger(__name__) + class AiohuesyncboxException(Exception): """Base error for aiohuesyncbox.""" @@ -36,4 +40,5 @@ class InvalidState(AiohuesyncboxException): def raise_error(code: int, message: str) -> None: cls = ERRORS.get(code, AiohuesyncboxException) + logger.debug("raise_error, %s, %s, %s" % (code, message, cls)) raise cls("{}: {}".format(code, message)) From 56db2407d3e398fcb1f72e1c2260bb2263feac62 Mon Sep 17 00:00:00 2001 From: Michel van de Wetering Date: Thu, 18 Apr 2024 20:40:04 +0200 Subject: [PATCH 4/4] Let logger format message (is faster) --- aiohuesyncbox/errors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiohuesyncbox/errors.py b/aiohuesyncbox/errors.py index d71a9bf..8d32ecb 100644 --- a/aiohuesyncbox/errors.py +++ b/aiohuesyncbox/errors.py @@ -40,5 +40,5 @@ class InvalidState(AiohuesyncboxException): def raise_error(code: int, message: str) -> None: cls = ERRORS.get(code, AiohuesyncboxException) - logger.debug("raise_error, %s, %s, %s" % (code, message, cls)) + logger.debug("raise_error, %s, %s, %s", code, message, cls) raise cls("{}: {}".format(code, message))