From 138bcad2cfe314a15755b905075a17556d95f485 Mon Sep 17 00:00:00 2001 From: Andrew Clemons Date: Fri, 16 Feb 2024 15:18:24 +0900 Subject: [PATCH] Separate request and response logging into other named loggers. I'd like to make the logging for aiodynamo louder at times for debugging or to generally see in application logs when a throttle or a timeout or something happened. For that, I need to set the log level to debug, but this also enables request and response payload logging which becomes very noisy and also smears potentially unwanted data into my log streams. I made two other loggets so the levels for those two things can be set at a different level to all the other logging done by aiodynamo. --- src/aiodynamo/client.py | 6 +++--- src/aiodynamo/utils.py | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/aiodynamo/client.py b/src/aiodynamo/client.py index cc66865..79dff6c 100644 --- a/src/aiodynamo/client.py +++ b/src/aiodynamo/client.py @@ -70,7 +70,7 @@ ) from .sign import signed_dynamo_request from .types import Item, NumericTypeConverter, TableName -from .utils import dy2py, logger, py2dy, wait +from .utils import dy2py, logger, request_logger, response_logger, py2dy, wait @dataclass(frozen=True) @@ -984,7 +984,7 @@ async def send_request( region=self.region, endpoint=self.endpoint, ) - logger.debug("sending request %r", request) + request_logger.debug("sending request %r", request) try: response = await self.http( Request( @@ -1002,7 +1002,7 @@ async def send_request( logger.debug("request failed") exception = exc.inner continue - logger.debug("got response %r", response) + response_logger.debug("got response %r", response) if response.status == 200: return cast(Dict[str, Any], json.loads(response.body)) exception = exception_from_response(response.status, response.body) diff --git a/src/aiodynamo/utils.py b/src/aiodynamo/utils.py index 0258857..9a70fe9 100644 --- a/src/aiodynamo/utils.py +++ b/src/aiodynamo/utils.py @@ -28,6 +28,8 @@ T = TypeVar("T") logger = logging.getLogger("aiodynamo") +request_logger = logging.getLogger("aiodynamo.request") +response_logger = logging.getLogger("aiodynamo.response") def py2dy(data: Union[Item, None]) -> Union[DynamoItem, None]: