Skip to content

Commit 4bffc4e

Browse files
authored
PYTHON-4471 - Logging records should have a standard field order (#2247)
1 parent d1c1415 commit 4bffc4e

File tree

14 files changed

+90
-90
lines changed

14 files changed

+90
-90
lines changed

pymongo/asynchronous/bulk.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ async def write_command(
255255
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
256256
_debug_log(
257257
_COMMAND_LOGGER,
258-
clientId=client._topology_settings._topology_id,
259258
message=_CommandStatusMessage.STARTED,
259+
clientId=client._topology_settings._topology_id,
260260
command=cmd,
261261
commandName=next(iter(cmd)),
262262
databaseName=bwc.db_name,
@@ -276,8 +276,8 @@ async def write_command(
276276
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
277277
_debug_log(
278278
_COMMAND_LOGGER,
279-
clientId=client._topology_settings._topology_id,
280279
message=_CommandStatusMessage.SUCCEEDED,
280+
clientId=client._topology_settings._topology_id,
281281
durationMS=duration,
282282
reply=reply,
283283
commandName=next(iter(cmd)),
@@ -302,8 +302,8 @@ async def write_command(
302302
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
303303
_debug_log(
304304
_COMMAND_LOGGER,
305-
clientId=client._topology_settings._topology_id,
306305
message=_CommandStatusMessage.FAILED,
306+
clientId=client._topology_settings._topology_id,
307307
durationMS=duration,
308308
failure=failure,
309309
commandName=next(iter(cmd)),
@@ -340,8 +340,8 @@ async def unack_write(
340340
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
341341
_debug_log(
342342
_COMMAND_LOGGER,
343-
clientId=client._topology_settings._topology_id,
344343
message=_CommandStatusMessage.STARTED,
344+
clientId=client._topology_settings._topology_id,
345345
command=cmd,
346346
commandName=next(iter(cmd)),
347347
databaseName=bwc.db_name,
@@ -366,8 +366,8 @@ async def unack_write(
366366
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
367367
_debug_log(
368368
_COMMAND_LOGGER,
369-
clientId=client._topology_settings._topology_id,
370369
message=_CommandStatusMessage.SUCCEEDED,
370+
clientId=client._topology_settings._topology_id,
371371
durationMS=duration,
372372
reply=reply,
373373
commandName=next(iter(cmd)),
@@ -393,8 +393,8 @@ async def unack_write(
393393
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
394394
_debug_log(
395395
_COMMAND_LOGGER,
396-
clientId=client._topology_settings._topology_id,
397396
message=_CommandStatusMessage.FAILED,
397+
clientId=client._topology_settings._topology_id,
398398
durationMS=duration,
399399
failure=failure,
400400
commandName=next(iter(cmd)),

pymongo/asynchronous/client_bulk.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ async def write_command(
241241
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
242242
_debug_log(
243243
_COMMAND_LOGGER,
244-
clientId=client._topology_settings._topology_id,
245244
message=_CommandStatusMessage.STARTED,
245+
clientId=client._topology_settings._topology_id,
246246
command=cmd,
247247
commandName=next(iter(cmd)),
248248
databaseName=bwc.db_name,
@@ -262,8 +262,8 @@ async def write_command(
262262
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
263263
_debug_log(
264264
_COMMAND_LOGGER,
265-
clientId=client._topology_settings._topology_id,
266265
message=_CommandStatusMessage.SUCCEEDED,
266+
clientId=client._topology_settings._topology_id,
267267
durationMS=duration,
268268
reply=reply,
269269
commandName=next(iter(cmd)),
@@ -289,8 +289,8 @@ async def write_command(
289289
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
290290
_debug_log(
291291
_COMMAND_LOGGER,
292-
clientId=client._topology_settings._topology_id,
293292
message=_CommandStatusMessage.FAILED,
293+
clientId=client._topology_settings._topology_id,
294294
durationMS=duration,
295295
failure=failure,
296296
commandName=next(iter(cmd)),
@@ -330,8 +330,8 @@ async def unack_write(
330330
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
331331
_debug_log(
332332
_COMMAND_LOGGER,
333-
clientId=client._topology_settings._topology_id,
334333
message=_CommandStatusMessage.STARTED,
334+
clientId=client._topology_settings._topology_id,
335335
command=cmd,
336336
commandName=next(iter(cmd)),
337337
databaseName=bwc.db_name,
@@ -356,8 +356,8 @@ async def unack_write(
356356
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
357357
_debug_log(
358358
_COMMAND_LOGGER,
359-
clientId=client._topology_settings._topology_id,
360359
message=_CommandStatusMessage.SUCCEEDED,
360+
clientId=client._topology_settings._topology_id,
361361
durationMS=duration,
362362
reply=reply,
363363
commandName=next(iter(cmd)),
@@ -383,8 +383,8 @@ async def unack_write(
383383
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
384384
_debug_log(
385385
_COMMAND_LOGGER,
386-
clientId=client._topology_settings._topology_id,
387386
message=_CommandStatusMessage.FAILED,
387+
clientId=client._topology_settings._topology_id,
388388
durationMS=duration,
389389
failure=failure,
390390
commandName=next(iter(cmd)),

pymongo/asynchronous/monitor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,14 @@ async def _check_server(self) -> ServerDescription:
274274
if _SDAM_LOGGER.isEnabledFor(logging.DEBUG):
275275
_debug_log(
276276
_SDAM_LOGGER,
277+
message=_SDAMStatusMessage.HEARTBEAT_FAIL,
277278
topologyId=self._topology._topology_id,
278279
serverHost=address[0],
279280
serverPort=address[1],
280281
awaited=awaited,
281282
durationMS=duration * 1000,
282283
failure=error,
283284
driverConnectionId=self._conn_id,
284-
message=_SDAMStatusMessage.HEARTBEAT_FAIL,
285285
)
286286
await self._reset_connection()
287287
if isinstance(error, _OperationCancelled):
@@ -313,13 +313,13 @@ async def _check_once(self) -> ServerDescription:
313313
if _SDAM_LOGGER.isEnabledFor(logging.DEBUG):
314314
_debug_log(
315315
_SDAM_LOGGER,
316+
message=_SDAMStatusMessage.HEARTBEAT_START,
316317
topologyId=self._topology._topology_id,
317318
driverConnectionId=conn.id,
318319
serverConnectionId=conn.server_connection_id,
319320
serverHost=address[0],
320321
serverPort=address[1],
321322
awaited=awaited,
322-
message=_SDAMStatusMessage.HEARTBEAT_START,
323323
)
324324

325325
self._cancel_context = conn.cancel_context
@@ -339,6 +339,7 @@ async def _check_once(self) -> ServerDescription:
339339
if _SDAM_LOGGER.isEnabledFor(logging.DEBUG):
340340
_debug_log(
341341
_SDAM_LOGGER,
342+
message=_SDAMStatusMessage.HEARTBEAT_SUCCESS,
342343
topologyId=self._topology._topology_id,
343344
driverConnectionId=conn.id,
344345
serverConnectionId=conn.server_connection_id,
@@ -347,7 +348,6 @@ async def _check_once(self) -> ServerDescription:
347348
awaited=awaited,
348349
durationMS=round_trip_time * 1000,
349350
reply=response.document,
350-
message=_SDAMStatusMessage.HEARTBEAT_SUCCESS,
351351
)
352352
return sd
353353

pymongo/asynchronous/network.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ async def command(
163163
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
164164
_debug_log(
165165
_COMMAND_LOGGER,
166-
clientId=client._topology_settings._topology_id,
167166
message=_CommandStatusMessage.STARTED,
167+
clientId=client._topology_settings._topology_id,
168168
command=spec,
169169
commandName=next(iter(spec)),
170170
databaseName=dbname,
@@ -225,8 +225,8 @@ async def command(
225225
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
226226
_debug_log(
227227
_COMMAND_LOGGER,
228-
clientId=client._topology_settings._topology_id,
229228
message=_CommandStatusMessage.FAILED,
229+
clientId=client._topology_settings._topology_id,
230230
durationMS=duration,
231231
failure=failure,
232232
commandName=next(iter(spec)),
@@ -259,8 +259,8 @@ async def command(
259259
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
260260
_debug_log(
261261
_COMMAND_LOGGER,
262-
clientId=client._topology_settings._topology_id,
263262
message=_CommandStatusMessage.SUCCEEDED,
263+
clientId=client._topology_settings._topology_id,
264264
durationMS=duration,
265265
reply=response_doc,
266266
commandName=next(iter(spec)),

pymongo/asynchronous/pool.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,8 @@ async def authenticate(self, reauthenticate: bool = False) -> None:
528528
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
529529
_debug_log(
530530
_CONNECTION_LOGGER,
531-
clientId=self._client_id,
532531
message=_ConnectionStatusMessage.CONN_READY,
532+
clientId=self._client_id,
533533
serverHost=self.address[0],
534534
serverPort=self.address[1],
535535
driverConnectionId=self.id,
@@ -561,8 +561,8 @@ async def close_conn(self, reason: Optional[str]) -> None:
561561
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
562562
_debug_log(
563563
_CONNECTION_LOGGER,
564-
clientId=self._client_id,
565564
message=_ConnectionStatusMessage.CONN_CLOSED,
565+
clientId=self._client_id,
566566
serverHost=self.address[0],
567567
serverPort=self.address[1],
568568
driverConnectionId=self.id,
@@ -777,8 +777,8 @@ def __init__(
777777
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
778778
_debug_log(
779779
_CONNECTION_LOGGER,
780-
clientId=self._client_id,
781780
message=_ConnectionStatusMessage.POOL_CREATED,
781+
clientId=self._client_id,
782782
serverHost=self.address[0],
783783
serverPort=self.address[1],
784784
**self.opts.non_default_options,
@@ -803,8 +803,8 @@ async def ready(self) -> None:
803803
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
804804
_debug_log(
805805
_CONNECTION_LOGGER,
806-
clientId=self._client_id,
807806
message=_ConnectionStatusMessage.POOL_READY,
807+
clientId=self._client_id,
808808
serverHost=self.address[0],
809809
serverPort=self.address[1],
810810
)
@@ -868,8 +868,8 @@ async def _reset(
868868
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
869869
_debug_log(
870870
_CONNECTION_LOGGER,
871-
clientId=self._client_id,
872871
message=_ConnectionStatusMessage.POOL_CLOSED,
872+
clientId=self._client_id,
873873
serverHost=self.address[0],
874874
serverPort=self.address[1],
875875
)
@@ -885,8 +885,8 @@ async def _reset(
885885
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
886886
_debug_log(
887887
_CONNECTION_LOGGER,
888-
clientId=self._client_id,
889888
message=_ConnectionStatusMessage.POOL_CLEARED,
889+
clientId=self._client_id,
890890
serverHost=self.address[0],
891891
serverPort=self.address[1],
892892
serviceId=service_id,
@@ -998,8 +998,8 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
998998
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
999999
_debug_log(
10001000
_CONNECTION_LOGGER,
1001-
clientId=self._client_id,
10021001
message=_ConnectionStatusMessage.CONN_CREATED,
1002+
clientId=self._client_id,
10031003
serverHost=self.address[0],
10041004
serverPort=self.address[1],
10051005
driverConnectionId=conn_id,
@@ -1019,8 +1019,8 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
10191019
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
10201020
_debug_log(
10211021
_CONNECTION_LOGGER,
1022-
clientId=self._client_id,
10231022
message=_ConnectionStatusMessage.CONN_CLOSED,
1023+
clientId=self._client_id,
10241024
serverHost=self.address[0],
10251025
serverPort=self.address[1],
10261026
driverConnectionId=conn_id,
@@ -1086,8 +1086,8 @@ async def checkout(
10861086
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
10871087
_debug_log(
10881088
_CONNECTION_LOGGER,
1089-
clientId=self._client_id,
10901089
message=_ConnectionStatusMessage.CHECKOUT_STARTED,
1090+
clientId=self._client_id,
10911091
serverHost=self.address[0],
10921092
serverPort=self.address[1],
10931093
)
@@ -1101,8 +1101,8 @@ async def checkout(
11011101
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
11021102
_debug_log(
11031103
_CONNECTION_LOGGER,
1104-
clientId=self._client_id,
11051104
message=_ConnectionStatusMessage.CHECKOUT_SUCCEEDED,
1105+
clientId=self._client_id,
11061106
serverHost=self.address[0],
11071107
serverPort=self.address[1],
11081108
driverConnectionId=conn.id,
@@ -1150,8 +1150,8 @@ def _raise_if_not_ready(self, checkout_started_time: float, emit_event: bool) ->
11501150
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
11511151
_debug_log(
11521152
_CONNECTION_LOGGER,
1153-
clientId=self._client_id,
11541153
message=_ConnectionStatusMessage.CHECKOUT_FAILED,
1154+
clientId=self._client_id,
11551155
serverHost=self.address[0],
11561156
serverPort=self.address[1],
11571157
reason="An error occurred while trying to establish a new connection",
@@ -1184,8 +1184,8 @@ async def _get_conn(
11841184
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
11851185
_debug_log(
11861186
_CONNECTION_LOGGER,
1187-
clientId=self._client_id,
11881187
message=_ConnectionStatusMessage.CHECKOUT_FAILED,
1188+
clientId=self._client_id,
11891189
serverHost=self.address[0],
11901190
serverPort=self.address[1],
11911191
reason="Connection pool was closed",
@@ -1280,8 +1280,8 @@ async def _get_conn(
12801280
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
12811281
_debug_log(
12821282
_CONNECTION_LOGGER,
1283-
clientId=self._client_id,
12841283
message=_ConnectionStatusMessage.CHECKOUT_FAILED,
1284+
clientId=self._client_id,
12851285
serverHost=self.address[0],
12861286
serverPort=self.address[1],
12871287
reason="An error occurred while trying to establish a new connection",
@@ -1313,8 +1313,8 @@ async def checkin(self, conn: AsyncConnection) -> None:
13131313
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
13141314
_debug_log(
13151315
_CONNECTION_LOGGER,
1316-
clientId=self._client_id,
13171316
message=_ConnectionStatusMessage.CHECKEDIN,
1317+
clientId=self._client_id,
13181318
serverHost=self.address[0],
13191319
serverPort=self.address[1],
13201320
driverConnectionId=conn.id,
@@ -1334,8 +1334,8 @@ async def checkin(self, conn: AsyncConnection) -> None:
13341334
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
13351335
_debug_log(
13361336
_CONNECTION_LOGGER,
1337-
clientId=self._client_id,
13381337
message=_ConnectionStatusMessage.CONN_CLOSED,
1338+
clientId=self._client_id,
13391339
serverHost=self.address[0],
13401340
serverPort=self.address[1],
13411341
driverConnectionId=conn.id,
@@ -1412,8 +1412,8 @@ def _raise_wait_queue_timeout(self, checkout_started_time: float) -> NoReturn:
14121412
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
14131413
_debug_log(
14141414
_CONNECTION_LOGGER,
1415-
clientId=self._client_id,
14161415
message=_ConnectionStatusMessage.CHECKOUT_FAILED,
1416+
clientId=self._client_id,
14171417
serverHost=self.address[0],
14181418
serverPort=self.address[1],
14191419
reason="Wait queue timeout elapsed without a connection becoming available",

pymongo/asynchronous/server.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ async def close(self) -> None:
108108
if _SDAM_LOGGER.isEnabledFor(logging.DEBUG):
109109
_debug_log(
110110
_SDAM_LOGGER,
111+
message=_SDAMStatusMessage.STOP_SERVER,
111112
topologyId=self._topology_id,
112113
serverHost=self._description.address[0],
113114
serverPort=self._description.address[1],
114-
message=_SDAMStatusMessage.STOP_SERVER,
115115
)
116116

117117
await self._monitor.close()
@@ -173,8 +173,8 @@ async def run_operation(
173173
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
174174
_debug_log(
175175
_COMMAND_LOGGER,
176-
clientId=client._topology_settings._topology_id,
177176
message=_CommandStatusMessage.STARTED,
177+
clientId=client._topology_settings._topology_id,
178178
command=cmd,
179179
commandName=next(iter(cmd)),
180180
databaseName=dbn,
@@ -234,8 +234,8 @@ async def run_operation(
234234
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
235235
_debug_log(
236236
_COMMAND_LOGGER,
237-
clientId=client._topology_settings._topology_id,
238237
message=_CommandStatusMessage.FAILED,
238+
clientId=client._topology_settings._topology_id,
239239
durationMS=duration,
240240
failure=failure,
241241
commandName=next(iter(cmd)),
@@ -278,8 +278,8 @@ async def run_operation(
278278
if _COMMAND_LOGGER.isEnabledFor(logging.DEBUG):
279279
_debug_log(
280280
_COMMAND_LOGGER,
281-
clientId=client._topology_settings._topology_id,
282281
message=_CommandStatusMessage.SUCCEEDED,
282+
clientId=client._topology_settings._topology_id,
283283
durationMS=duration,
284284
reply=res,
285285
commandName=next(iter(cmd)),

0 commit comments

Comments
 (0)