Skip to content
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
2 changes: 1 addition & 1 deletion test/asynchronous/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def test_detected_environment_logging(self, mock_get_hosts):
mock_get_hosts.return_value = [(host, 1)]
AsyncMongoClient(host)
AsyncMongoClient(multi_host)
logs = [record.message for record in cm.records if record.name == "pymongo.client"]
logs = [record.getMessage() for record in cm.records if record.name == "pymongo.client"]
self.assertEqual(len(logs), 7)

@patch("pymongo.srv_resolver._SrvResolver.get_hosts")
Expand Down
14 changes: 7 additions & 7 deletions test/asynchronous/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ async def test_default_truncation_limit(self):
with self.assertLogs("pymongo.command", level="DEBUG") as cm:
await db.test.insert_many(docs)

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

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

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

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

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

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

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

cmd_started_log = cmd_started_log[:-3]
last_3_bytes = cmd_started_log.encode()[-3:].decode()
Expand Down
2 changes: 1 addition & 1 deletion test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ def test_detected_environment_logging(self, mock_get_hosts):
mock_get_hosts.return_value = [(host, 1)]
MongoClient(host)
MongoClient(multi_host)
logs = [record.message for record in cm.records if record.name == "pymongo.client"]
logs = [record.getMessage() for record in cm.records if record.name == "pymongo.client"]
self.assertEqual(len(logs), 7)

@patch("pymongo.srv_resolver._SrvResolver.get_hosts")
Expand Down
14 changes: 7 additions & 7 deletions test/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ def test_default_truncation_limit(self):
with self.assertLogs("pymongo.command", level="DEBUG") as cm:
db.test.insert_many(docs)

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

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

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

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

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

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

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

cmd_started_log = cmd_started_log[:-3]
last_3_bytes = cmd_started_log.encode()[-3:].decode()
Expand Down
2 changes: 1 addition & 1 deletion test/unified_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,7 @@ def format_logs(log_list):
for log in log_list:
if log.module == "ocsp_support":
continue
data = json_util.loads(log.message)
data = json_util.loads(log.getMessage())
client = data.pop("clientId") if "clientId" in data else data.pop("topologyId")
client_to_log[client].append(
{
Expand Down
Loading