Skip to content

Commit f4f8ae4

Browse files
committed
Update log format.
1 parent f15aa86 commit f4f8ae4

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

ldclient/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def __register_plugins(self, environment_metadata: EnvironmentMetadata):
316316
try:
317317
plugin.register(self, environment_metadata)
318318
except Exception as e:
319-
log.error(f"Error registering plugin {plugin.metadata.name}: {e}")
319+
log.error("Error registering plugin %s: %s", plugin.metadata.name, e)
320320

321321
def _set_event_processor(self, config):
322322
if config.offline or not config.send_events:

ldclient/testing/test_ldclient_plugin.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,13 @@ def test_plugin_error_handling_get_hooks(self):
201201

202202
# Verify that the error was logged with the correct message
203203
mock_log_error.assert_called_once()
204-
error_call_args = mock_log_error.call_args[0]
205-
self.assertIn("Error getting hooks from plugin Error Plugin", error_call_args[0])
206-
self.assertIn("Get hooks error in Error Plugin", str(error_call_args))
204+
# Check the format string and arguments separately
205+
format_string = mock_log_error.call_args[0][0]
206+
format_args = mock_log_error.call_args[0][1:]
207+
self.assertEqual(format_string, "Error getting hooks from plugin %s: %s")
208+
self.assertEqual(len(format_args), 2)
209+
self.assertEqual(format_args[0], "Error Plugin")
210+
self.assertIn("Get hooks error in Error Plugin", str(format_args[1]))
207211

208212
def test_plugin_error_handling_register(self):
209213
"""Test that errors during plugin registration are handled gracefully."""
@@ -237,9 +241,13 @@ def test_plugin_error_handling_register(self):
237241

238242
# Verify that the error was logged with the correct message
239243
mock_log_error.assert_called_once()
240-
error_call_args = mock_log_error.call_args[0]
241-
self.assertIn("Error registering plugin Error Plugin", error_call_args[0])
242-
self.assertIn("Registration error in Error Plugin", str(error_call_args))
244+
# Check the format string and arguments separately
245+
format_string = mock_log_error.call_args[0][0]
246+
format_args = mock_log_error.call_args[0][1:]
247+
self.assertEqual(format_string, "Error registering plugin %s: %s")
248+
self.assertEqual(len(format_args), 2)
249+
self.assertEqual(format_args[0], "Error Plugin")
250+
self.assertIn("Registration error in Error Plugin", str(format_args[1]))
243251

244252
def test_plugin_with_existing_hooks(self):
245253
"""Test that plugin hooks work alongside existing hooks and config hooks are called before plugin hooks."""

0 commit comments

Comments
 (0)