diff --git a/src/neo4j/_async/io/_bolt.py b/src/neo4j/_async/io/_bolt.py index 339c065f..b3e485d4 100644 --- a/src/neo4j/_async/io/_bolt.py +++ b/src/neo4j/_async/io/_bolt.py @@ -1029,12 +1029,23 @@ async def _set_defunct(self, message, error=None, silent=False): direct_driver = getattr(self.pool, "is_direct_pool", False) user_cancelled = isinstance(error, asyncio.CancelledError) + if not (user_cancelled or self._closing): + log_call = log.error + else: + log_call = log.debug if error: - log.debug( - "[#%04X] _: error: %r", self.local_port, error + log_call( + "[#%04X] _: error: %s: %r", + self.local_port, + message, + error, + ) + else: + log_call( + "[#%04X] _: error: %s", + self.local_port, + message, ) - if not user_cancelled: - log.error(message) # We were attempting to receive data but the connection # has unexpectedly terminated. So, we need to close the # connection from the client side, and remove the address diff --git a/src/neo4j/_sync/io/_bolt.py b/src/neo4j/_sync/io/_bolt.py index f1176ba0..2ad1790a 100644 --- a/src/neo4j/_sync/io/_bolt.py +++ b/src/neo4j/_sync/io/_bolt.py @@ -1029,12 +1029,23 @@ def _set_defunct(self, message, error=None, silent=False): direct_driver = getattr(self.pool, "is_direct_pool", False) user_cancelled = isinstance(error, asyncio.CancelledError) + if not (user_cancelled or self._closing): + log_call = log.error + else: + log_call = log.debug if error: - log.debug( - "[#%04X] _: error: %r", self.local_port, error + log_call( + "[#%04X] _: error: %s: %r", + self.local_port, + message, + error, + ) + else: + log_call( + "[#%04X] _: error: %s", + self.local_port, + message, ) - if not user_cancelled: - log.error(message) # We were attempting to receive data but the connection # has unexpectedly terminated. So, we need to close the # connection from the client side, and remove the address