Skip to content

Commit 29bbf77

Browse files
authored
PYTHON-4607 Use LogRecord.getMessage() not LogRecord.message (#1837)
1 parent 25f724b commit 29bbf77

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

test/asynchronous/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ def test_detected_environment_logging(self, mock_get_hosts):
617617
mock_get_hosts.return_value = [(host, 1)]
618618
AsyncMongoClient(host)
619619
AsyncMongoClient(multi_host)
620-
logs = [record.message for record in cm.records if record.name == "pymongo.client"]
620+
logs = [record.getMessage() for record in cm.records if record.name == "pymongo.client"]
621621
self.assertEqual(len(logs), 7)
622622

623623
@patch("pymongo.srv_resolver._SrvResolver.get_hosts")

test/asynchronous/test_logger.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ async def test_default_truncation_limit(self):
3737
with self.assertLogs("pymongo.command", level="DEBUG") as cm:
3838
await db.test.insert_many(docs)
3939

40-
cmd_started_log = json_util.loads(cm.records[0].message)
40+
cmd_started_log = json_util.loads(cm.records[0].getMessage())
4141
self.assertEqual(len(cmd_started_log["command"]), _DEFAULT_DOCUMENT_LENGTH + 3)
4242

43-
cmd_succeeded_log = json_util.loads(cm.records[1].message)
43+
cmd_succeeded_log = json_util.loads(cm.records[1].getMessage())
4444
self.assertLessEqual(len(cmd_succeeded_log["reply"]), _DEFAULT_DOCUMENT_LENGTH + 3)
4545

4646
with self.assertLogs("pymongo.command", level="DEBUG") as cm:
4747
await db.test.find({}).to_list()
48-
cmd_succeeded_log = json_util.loads(cm.records[1].message)
48+
cmd_succeeded_log = json_util.loads(cm.records[1].getMessage())
4949
self.assertEqual(len(cmd_succeeded_log["reply"]), _DEFAULT_DOCUMENT_LENGTH + 3)
5050

5151
async def test_configured_truncation_limit(self):
@@ -55,14 +55,14 @@ async def test_configured_truncation_limit(self):
5555
with self.assertLogs("pymongo.command", level="DEBUG") as cm:
5656
await db.command(cmd)
5757

58-
cmd_started_log = json_util.loads(cm.records[0].message)
58+
cmd_started_log = json_util.loads(cm.records[0].getMessage())
5959
self.assertEqual(len(cmd_started_log["command"]), 5 + 3)
6060

61-
cmd_succeeded_log = json_util.loads(cm.records[1].message)
61+
cmd_succeeded_log = json_util.loads(cm.records[1].getMessage())
6262
self.assertLessEqual(len(cmd_succeeded_log["reply"]), 5 + 3)
6363
with self.assertRaises(OperationFailure):
6464
await db.command({"notARealCommand": True})
65-
cmd_failed_log = json_util.loads(cm.records[-1].message)
65+
cmd_failed_log = json_util.loads(cm.records[-1].getMessage())
6666
self.assertEqual(len(cmd_failed_log["failure"]), 5 + 3)
6767

6868
async def test_truncation_multi_byte_codepoints(self):
@@ -78,7 +78,7 @@ async def test_truncation_multi_byte_codepoints(self):
7878
with patch.dict("os.environ", {"MONGOB_LOG_MAX_DOCUMENT_LENGTH": length}):
7979
with self.assertLogs("pymongo.command", level="DEBUG") as cm:
8080
await self.db.test.insert_one({"x": multi_byte_char_str})
81-
cmd_started_log = json_util.loads(cm.records[0].message)["command"]
81+
cmd_started_log = json_util.loads(cm.records[0].getMessage())["command"]
8282

8383
cmd_started_log = cmd_started_log[:-3]
8484
last_3_bytes = cmd_started_log.encode()[-3:].decode()

test/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ def test_detected_environment_logging(self, mock_get_hosts):
611611
mock_get_hosts.return_value = [(host, 1)]
612612
MongoClient(host)
613613
MongoClient(multi_host)
614-
logs = [record.message for record in cm.records if record.name == "pymongo.client"]
614+
logs = [record.getMessage() for record in cm.records if record.name == "pymongo.client"]
615615
self.assertEqual(len(logs), 7)
616616

617617
@patch("pymongo.srv_resolver._SrvResolver.get_hosts")

test/test_logger.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ def test_default_truncation_limit(self):
3636
with self.assertLogs("pymongo.command", level="DEBUG") as cm:
3737
db.test.insert_many(docs)
3838

39-
cmd_started_log = json_util.loads(cm.records[0].message)
39+
cmd_started_log = json_util.loads(cm.records[0].getMessage())
4040
self.assertEqual(len(cmd_started_log["command"]), _DEFAULT_DOCUMENT_LENGTH + 3)
4141

42-
cmd_succeeded_log = json_util.loads(cm.records[1].message)
42+
cmd_succeeded_log = json_util.loads(cm.records[1].getMessage())
4343
self.assertLessEqual(len(cmd_succeeded_log["reply"]), _DEFAULT_DOCUMENT_LENGTH + 3)
4444

4545
with self.assertLogs("pymongo.command", level="DEBUG") as cm:
4646
db.test.find({}).to_list()
47-
cmd_succeeded_log = json_util.loads(cm.records[1].message)
47+
cmd_succeeded_log = json_util.loads(cm.records[1].getMessage())
4848
self.assertEqual(len(cmd_succeeded_log["reply"]), _DEFAULT_DOCUMENT_LENGTH + 3)
4949

5050
def test_configured_truncation_limit(self):
@@ -54,14 +54,14 @@ def test_configured_truncation_limit(self):
5454
with self.assertLogs("pymongo.command", level="DEBUG") as cm:
5555
db.command(cmd)
5656

57-
cmd_started_log = json_util.loads(cm.records[0].message)
57+
cmd_started_log = json_util.loads(cm.records[0].getMessage())
5858
self.assertEqual(len(cmd_started_log["command"]), 5 + 3)
5959

60-
cmd_succeeded_log = json_util.loads(cm.records[1].message)
60+
cmd_succeeded_log = json_util.loads(cm.records[1].getMessage())
6161
self.assertLessEqual(len(cmd_succeeded_log["reply"]), 5 + 3)
6262
with self.assertRaises(OperationFailure):
6363
db.command({"notARealCommand": True})
64-
cmd_failed_log = json_util.loads(cm.records[-1].message)
64+
cmd_failed_log = json_util.loads(cm.records[-1].getMessage())
6565
self.assertEqual(len(cmd_failed_log["failure"]), 5 + 3)
6666

6767
def test_truncation_multi_byte_codepoints(self):
@@ -77,7 +77,7 @@ def test_truncation_multi_byte_codepoints(self):
7777
with patch.dict("os.environ", {"MONGOB_LOG_MAX_DOCUMENT_LENGTH": length}):
7878
with self.assertLogs("pymongo.command", level="DEBUG") as cm:
7979
self.db.test.insert_one({"x": multi_byte_char_str})
80-
cmd_started_log = json_util.loads(cm.records[0].message)["command"]
80+
cmd_started_log = json_util.loads(cm.records[0].getMessage())["command"]
8181

8282
cmd_started_log = cmd_started_log[:-3]
8383
last_3_bytes = cmd_started_log.encode()[-3:].decode()

test/unified_format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1925,7 +1925,7 @@ def format_logs(log_list):
19251925
for log in log_list:
19261926
if log.module == "ocsp_support":
19271927
continue
1928-
data = json_util.loads(log.message)
1928+
data = json_util.loads(log.getMessage())
19291929
client = data.pop("clientId") if "clientId" in data else data.pop("topologyId")
19301930
client_to_log[client].append(
19311931
{

0 commit comments

Comments
 (0)