Add checks for debug logging in the write path (#458)

This commit is contained in:
J. Nick Koston 2023-07-03 19:54:22 -05:00 committed by GitHub
parent 87e580914f
commit 69b4c42cf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -139,7 +139,8 @@ class APIPlaintextFrameHelper(APIFrameHelper):
"""
assert self._transport is not None, "Transport should be set"
data = b"\0" + varuint_to_bytes(len(data)) + varuint_to_bytes(type_) + data
_LOGGER.debug("Sending plaintext frame %s", data.hex())
if _LOGGER.isEnabledFor(logging.DEBUG):
_LOGGER.debug("Sending plaintext frame %s", data.hex())
try:
self._transport.write(data)

View File

@ -531,7 +531,11 @@ class APIConnection:
if not message_type:
raise ValueError(f"Message type id not found for type {type(msg)}")
encoded = msg.SerializeToString()
_LOGGER.debug("%s: Sending %s: %s", self._params.address, type(msg), str(msg))
if _LOGGER.isEnabledFor(logging.DEBUG):
_LOGGER.debug(
"%s: Sending %s: %s", self._params.address, type(msg), str(msg)
)
try:
frame_helper.write_packet(message_type, encoded)