Skip to content

Commit

Permalink
Separate request and response logging into other named loggers.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aclemons committed Feb 16, 2024
1 parent eb5814e commit 138bcad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/aiodynamo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/aiodynamo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down

0 comments on commit 138bcad

Please sign in to comment.