Skip to content

PYTHON-4471 - Logging records should have a standard field order #2247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pymongo/asynchronous/bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ async def write_command(
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_COMMAND_LOGGER,
clientId=client._topology_settings._topology_id,
message=_CommandStatusMessage.STARTED,
clientId=client._topology_settings._topology_id,
command=cmd,
commandName=next(iter(cmd)),
databaseName=bwc.db_name,
Expand All @@ -276,8 +276,8 @@ async def write_command(
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_COMMAND_LOGGER,
clientId=client._topology_settings._topology_id,
message=_CommandStatusMessage.SUCCEEDED,
clientId=client._topology_settings._topology_id,
durationMS=duration,
reply=reply,
commandName=next(iter(cmd)),
Expand All @@ -302,8 +302,8 @@ async def write_command(
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_COMMAND_LOGGER,
clientId=client._topology_settings._topology_id,
message=_CommandStatusMessage.FAILED,
clientId=client._topology_settings._topology_id,
durationMS=duration,
failure=failure,
commandName=next(iter(cmd)),
Expand Down Expand Up @@ -340,8 +340,8 @@ async def unack_write(
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_COMMAND_LOGGER,
clientId=client._topology_settings._topology_id,
message=_CommandStatusMessage.STARTED,
clientId=client._topology_settings._topology_id,
command=cmd,
commandName=next(iter(cmd)),
databaseName=bwc.db_name,
Expand All @@ -366,8 +366,8 @@ async def unack_write(
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_COMMAND_LOGGER,
clientId=client._topology_settings._topology_id,
message=_CommandStatusMessage.SUCCEEDED,
clientId=client._topology_settings._topology_id,
durationMS=duration,
reply=reply,
commandName=next(iter(cmd)),
Expand All @@ -393,8 +393,8 @@ async def unack_write(
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_COMMAND_LOGGER,
clientId=client._topology_settings._topology_id,
message=_CommandStatusMessage.FAILED,
clientId=client._topology_settings._topology_id,
durationMS=duration,
failure=failure,
commandName=next(iter(cmd)),
Expand Down
12 changes: 6 additions & 6 deletions pymongo/asynchronous/client_bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ async def write_command(
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_COMMAND_LOGGER,
clientId=client._topology_settings._topology_id,
message=_CommandStatusMessage.STARTED,
clientId=client._topology_settings._topology_id,
command=cmd,
commandName=next(iter(cmd)),
databaseName=bwc.db_name,
Expand All @@ -262,8 +262,8 @@ async def write_command(
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_COMMAND_LOGGER,
clientId=client._topology_settings._topology_id,
message=_CommandStatusMessage.SUCCEEDED,
clientId=client._topology_settings._topology_id,
durationMS=duration,
reply=reply,
commandName=next(iter(cmd)),
Expand All @@ -289,8 +289,8 @@ async def write_command(
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_COMMAND_LOGGER,
clientId=client._topology_settings._topology_id,
message=_CommandStatusMessage.FAILED,
clientId=client._topology_settings._topology_id,
durationMS=duration,
failure=failure,
commandName=next(iter(cmd)),
Expand Down Expand Up @@ -330,8 +330,8 @@ async def unack_write(
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_COMMAND_LOGGER,
clientId=client._topology_settings._topology_id,
message=_CommandStatusMessage.STARTED,
clientId=client._topology_settings._topology_id,
command=cmd,
commandName=next(iter(cmd)),
databaseName=bwc.db_name,
Expand All @@ -356,8 +356,8 @@ async def unack_write(
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_COMMAND_LOGGER,
clientId=client._topology_settings._topology_id,
message=_CommandStatusMessage.SUCCEEDED,
clientId=client._topology_settings._topology_id,
durationMS=duration,
reply=reply,
commandName=next(iter(cmd)),
Expand All @@ -383,8 +383,8 @@ async def unack_write(
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_COMMAND_LOGGER,
clientId=client._topology_settings._topology_id,
message=_CommandStatusMessage.FAILED,
clientId=client._topology_settings._topology_id,
durationMS=duration,
failure=failure,
commandName=next(iter(cmd)),
Expand Down
6 changes: 3 additions & 3 deletions pymongo/asynchronous/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,14 @@ async def _check_server(self) -> ServerDescription:
if _SDAM_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_SDAM_LOGGER,
message=_SDAMStatusMessage.HEARTBEAT_FAIL,
topologyId=self._topology._topology_id,
serverHost=address[0],
serverPort=address[1],
awaited=awaited,
durationMS=duration * 1000,
failure=error,
driverConnectionId=self._conn_id,
message=_SDAMStatusMessage.HEARTBEAT_FAIL,
)
await self._reset_connection()
if isinstance(error, _OperationCancelled):
Expand Down Expand Up @@ -313,13 +313,13 @@ async def _check_once(self) -> ServerDescription:
if _SDAM_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_SDAM_LOGGER,
message=_SDAMStatusMessage.HEARTBEAT_START,
topologyId=self._topology._topology_id,
driverConnectionId=conn.id,
serverConnectionId=conn.server_connection_id,
serverHost=address[0],
serverPort=address[1],
awaited=awaited,
message=_SDAMStatusMessage.HEARTBEAT_START,
)

self._cancel_context = conn.cancel_context
Expand All @@ -339,6 +339,7 @@ async def _check_once(self) -> ServerDescription:
if _SDAM_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_SDAM_LOGGER,
message=_SDAMStatusMessage.HEARTBEAT_SUCCESS,
topologyId=self._topology._topology_id,
driverConnectionId=conn.id,
serverConnectionId=conn.server_connection_id,
Expand All @@ -347,7 +348,6 @@ async def _check_once(self) -> ServerDescription:
awaited=awaited,
durationMS=round_trip_time * 1000,
reply=response.document,
message=_SDAMStatusMessage.HEARTBEAT_SUCCESS,
)
return sd

Expand Down
6 changes: 3 additions & 3 deletions pymongo/asynchronous/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ async def command(
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_COMMAND_LOGGER,
clientId=client._topology_settings._topology_id,
message=_CommandStatusMessage.STARTED,
clientId=client._topology_settings._topology_id,
command=spec,
commandName=next(iter(spec)),
databaseName=dbname,
Expand Down Expand Up @@ -225,8 +225,8 @@ async def command(
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_COMMAND_LOGGER,
clientId=client._topology_settings._topology_id,
message=_CommandStatusMessage.FAILED,
clientId=client._topology_settings._topology_id,
durationMS=duration,
failure=failure,
commandName=next(iter(spec)),
Expand Down Expand Up @@ -259,8 +259,8 @@ async def command(
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_COMMAND_LOGGER,
clientId=client._topology_settings._topology_id,
message=_CommandStatusMessage.SUCCEEDED,
clientId=client._topology_settings._topology_id,
durationMS=duration,
reply=response_doc,
commandName=next(iter(spec)),
Expand Down
32 changes: 16 additions & 16 deletions pymongo/asynchronous/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,8 @@ async def authenticate(self, reauthenticate: bool = False) -> None:
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_CONNECTION_LOGGER,
clientId=self._client_id,
message=_ConnectionStatusMessage.CONN_READY,
clientId=self._client_id,
serverHost=self.address[0],
serverPort=self.address[1],
driverConnectionId=self.id,
Expand Down Expand Up @@ -561,8 +561,8 @@ async def close_conn(self, reason: Optional[str]) -> None:
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_CONNECTION_LOGGER,
clientId=self._client_id,
message=_ConnectionStatusMessage.CONN_CLOSED,
clientId=self._client_id,
serverHost=self.address[0],
serverPort=self.address[1],
driverConnectionId=self.id,
Expand Down Expand Up @@ -777,8 +777,8 @@ def __init__(
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_CONNECTION_LOGGER,
clientId=self._client_id,
message=_ConnectionStatusMessage.POOL_CREATED,
clientId=self._client_id,
serverHost=self.address[0],
serverPort=self.address[1],
**self.opts.non_default_options,
Expand All @@ -803,8 +803,8 @@ async def ready(self) -> None:
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_CONNECTION_LOGGER,
clientId=self._client_id,
message=_ConnectionStatusMessage.POOL_READY,
clientId=self._client_id,
serverHost=self.address[0],
serverPort=self.address[1],
)
Expand Down Expand Up @@ -868,8 +868,8 @@ async def _reset(
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_CONNECTION_LOGGER,
clientId=self._client_id,
message=_ConnectionStatusMessage.POOL_CLOSED,
clientId=self._client_id,
serverHost=self.address[0],
serverPort=self.address[1],
)
Expand All @@ -885,8 +885,8 @@ async def _reset(
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_CONNECTION_LOGGER,
clientId=self._client_id,
message=_ConnectionStatusMessage.POOL_CLEARED,
clientId=self._client_id,
serverHost=self.address[0],
serverPort=self.address[1],
serviceId=service_id,
Expand Down Expand Up @@ -998,8 +998,8 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_CONNECTION_LOGGER,
clientId=self._client_id,
message=_ConnectionStatusMessage.CONN_CREATED,
clientId=self._client_id,
serverHost=self.address[0],
serverPort=self.address[1],
driverConnectionId=conn_id,
Expand All @@ -1019,8 +1019,8 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_CONNECTION_LOGGER,
clientId=self._client_id,
message=_ConnectionStatusMessage.CONN_CLOSED,
clientId=self._client_id,
serverHost=self.address[0],
serverPort=self.address[1],
driverConnectionId=conn_id,
Expand Down Expand Up @@ -1086,8 +1086,8 @@ async def checkout(
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_CONNECTION_LOGGER,
clientId=self._client_id,
message=_ConnectionStatusMessage.CHECKOUT_STARTED,
clientId=self._client_id,
serverHost=self.address[0],
serverPort=self.address[1],
)
Expand All @@ -1101,8 +1101,8 @@ async def checkout(
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_CONNECTION_LOGGER,
clientId=self._client_id,
message=_ConnectionStatusMessage.CHECKOUT_SUCCEEDED,
clientId=self._client_id,
serverHost=self.address[0],
serverPort=self.address[1],
driverConnectionId=conn.id,
Expand Down Expand Up @@ -1150,8 +1150,8 @@ def _raise_if_not_ready(self, checkout_started_time: float, emit_event: bool) ->
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_CONNECTION_LOGGER,
clientId=self._client_id,
message=_ConnectionStatusMessage.CHECKOUT_FAILED,
clientId=self._client_id,
serverHost=self.address[0],
serverPort=self.address[1],
reason="An error occurred while trying to establish a new connection",
Expand Down Expand Up @@ -1184,8 +1184,8 @@ async def _get_conn(
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_CONNECTION_LOGGER,
clientId=self._client_id,
message=_ConnectionStatusMessage.CHECKOUT_FAILED,
clientId=self._client_id,
serverHost=self.address[0],
serverPort=self.address[1],
reason="Connection pool was closed",
Expand Down Expand Up @@ -1280,8 +1280,8 @@ async def _get_conn(
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_CONNECTION_LOGGER,
clientId=self._client_id,
message=_ConnectionStatusMessage.CHECKOUT_FAILED,
clientId=self._client_id,
serverHost=self.address[0],
serverPort=self.address[1],
reason="An error occurred while trying to establish a new connection",
Expand Down Expand Up @@ -1313,8 +1313,8 @@ async def checkin(self, conn: AsyncConnection) -> None:
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_CONNECTION_LOGGER,
clientId=self._client_id,
message=_ConnectionStatusMessage.CHECKEDIN,
clientId=self._client_id,
serverHost=self.address[0],
serverPort=self.address[1],
driverConnectionId=conn.id,
Expand All @@ -1334,8 +1334,8 @@ async def checkin(self, conn: AsyncConnection) -> None:
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_CONNECTION_LOGGER,
clientId=self._client_id,
message=_ConnectionStatusMessage.CONN_CLOSED,
clientId=self._client_id,
serverHost=self.address[0],
serverPort=self.address[1],
driverConnectionId=conn.id,
Expand Down Expand Up @@ -1412,8 +1412,8 @@ def _raise_wait_queue_timeout(self, checkout_started_time: float) -> NoReturn:
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_CONNECTION_LOGGER,
clientId=self._client_id,
message=_ConnectionStatusMessage.CHECKOUT_FAILED,
clientId=self._client_id,
serverHost=self.address[0],
serverPort=self.address[1],
reason="Wait queue timeout elapsed without a connection becoming available",
Expand Down
8 changes: 4 additions & 4 deletions pymongo/asynchronous/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ async def close(self) -> None:
if _SDAM_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_SDAM_LOGGER,
message=_SDAMStatusMessage.STOP_SERVER,
topologyId=self._topology_id,
serverHost=self._description.address[0],
serverPort=self._description.address[1],
message=_SDAMStatusMessage.STOP_SERVER,
)

await self._monitor.close()
Expand Down Expand Up @@ -173,8 +173,8 @@ async def run_operation(
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_COMMAND_LOGGER,
clientId=client._topology_settings._topology_id,
message=_CommandStatusMessage.STARTED,
clientId=client._topology_settings._topology_id,
command=cmd,
commandName=next(iter(cmd)),
databaseName=dbn,
Expand Down Expand Up @@ -234,8 +234,8 @@ async def run_operation(
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_COMMAND_LOGGER,
clientId=client._topology_settings._topology_id,
message=_CommandStatusMessage.FAILED,
clientId=client._topology_settings._topology_id,
durationMS=duration,
failure=failure,
commandName=next(iter(cmd)),
Expand Down Expand Up @@ -278,8 +278,8 @@ async def run_operation(
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_COMMAND_LOGGER,
clientId=client._topology_settings._topology_id,
message=_CommandStatusMessage.SUCCEEDED,
clientId=client._topology_settings._topology_id,
durationMS=duration,
reply=res,
commandName=next(iter(cmd)),
Expand Down
Loading
Loading