diff --git a/pymongo/logger.py b/pymongo/logger.py index 670c3fe5f..f5a8cf1e4 100644 --- a/pymongo/logger.py +++ b/pymongo/logger.py @@ -75,8 +75,8 @@ _VERBOSE_CONNECTION_ERROR_REASONS = { ConnectionClosedReason.POOL_CLOSED: "Connection pool was closed", ConnectionCheckOutFailedReason.POOL_CLOSED: "Connection pool was closed", ConnectionClosedReason.STALE: "Connection pool was stale", - ConnectionClosedReason.ERROR: "Connection experienced an error", - ConnectionCheckOutFailedReason.CONN_ERROR: "Connection experienced an error", + ConnectionClosedReason.ERROR: "An error occurred while using the connection", + ConnectionCheckOutFailedReason.CONN_ERROR: "An error occurred while trying to establish a new connection", ConnectionClosedReason.IDLE: "Connection was idle too long", ConnectionCheckOutFailedReason.TIMEOUT: "Connection exceeded the specified timeout", } diff --git a/pymongo/pool.py b/pymongo/pool.py index 8844f81b6..0ece6084c 100644 --- a/pymongo/pool.py +++ b/pymongo/pool.py @@ -1132,6 +1132,7 @@ class Connection: serverPort=self.address[1], driverConnectionId=self.id, reason=_verbose_connection_error_reason(reason), + error=reason, ) def _close_conn(self) -> None: @@ -1981,7 +1982,7 @@ class Pool: serverHost=self.address[0], serverPort=self.address[1], driverConnectionId=conn.id, - reason="An error occurred while using the connection", + reason=_verbose_connection_error_reason(ConnectionClosedReason.ERROR), error=ConnectionClosedReason.ERROR, ) else: diff --git a/test/connection_logging/connection-logging.json b/test/connection_logging/connection-logging.json index b3d48f56b..5b3f8c1d4 100644 --- a/test/connection_logging/connection-logging.json +++ b/test/connection_logging/connection-logging.json @@ -425,22 +425,6 @@ } } }, - { - "level": "debug", - "component": "connection", - "data": { - "message": "Connection pool cleared", - "serverHost": { - "$$type": "string" - }, - "serverPort": { - "$$type": [ - "int", - "long" - ] - } - } - }, { "level": "debug", "component": "connection", @@ -486,6 +470,22 @@ "$$exists": true } } + }, + { + "level": "debug", + "component": "connection", + "data": { + "message": "Connection pool cleared", + "serverHost": { + "$$type": "string" + }, + "serverPort": { + "$$type": [ + "int", + "long" + ] + } + } } ] }