Skip to content

Commit 3544c29

Browse files
authored
Improve connection error logging (#1109)
* Lower severity of connection error logging when closing the connection (the error is very likely to be ignored anyway) * Unify logging format
1 parent 0b1e872 commit 3544c29

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

src/neo4j/_async/io/_bolt.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,12 +1029,23 @@ async def _set_defunct(self, message, error=None, silent=False):
10291029
direct_driver = getattr(self.pool, "is_direct_pool", False)
10301030
user_cancelled = isinstance(error, asyncio.CancelledError)
10311031

1032+
if not (user_cancelled or self._closing):
1033+
log_call = log.error
1034+
else:
1035+
log_call = log.debug
10321036
if error:
1033-
log.debug(
1034-
"[#%04X] _: <CONNECTION> error: %r", self.local_port, error
1037+
log_call(
1038+
"[#%04X] _: <CONNECTION> error: %s: %r",
1039+
self.local_port,
1040+
message,
1041+
error,
1042+
)
1043+
else:
1044+
log_call(
1045+
"[#%04X] _: <CONNECTION> error: %s",
1046+
self.local_port,
1047+
message,
10351048
)
1036-
if not user_cancelled:
1037-
log.error(message)
10381049
# We were attempting to receive data but the connection
10391050
# has unexpectedly terminated. So, we need to close the
10401051
# connection from the client side, and remove the address

src/neo4j/_sync/io/_bolt.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,12 +1029,23 @@ def _set_defunct(self, message, error=None, silent=False):
10291029
direct_driver = getattr(self.pool, "is_direct_pool", False)
10301030
user_cancelled = isinstance(error, asyncio.CancelledError)
10311031

1032+
if not (user_cancelled or self._closing):
1033+
log_call = log.error
1034+
else:
1035+
log_call = log.debug
10321036
if error:
1033-
log.debug(
1034-
"[#%04X] _: <CONNECTION> error: %r", self.local_port, error
1037+
log_call(
1038+
"[#%04X] _: <CONNECTION> error: %s: %r",
1039+
self.local_port,
1040+
message,
1041+
error,
1042+
)
1043+
else:
1044+
log_call(
1045+
"[#%04X] _: <CONNECTION> error: %s",
1046+
self.local_port,
1047+
message,
10351048
)
1036-
if not user_cancelled:
1037-
log.error(message)
10381049
# We were attempting to receive data but the connection
10391050
# has unexpectedly terminated. So, we need to close the
10401051
# connection from the client side, and remove the address

0 commit comments

Comments
 (0)