Skip to content

Commit 892bf7a

Browse files
committed
[py] truncate large strings when logging requests
1 parent 8411a32 commit 892bf7a

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

py/selenium/webdriver/remote/remote_connection.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ def execute(self, command, params):
297297
del params[word]
298298
data = utils.dump_json(params)
299299
url = f"{self._url}{path}"
300+
trimmed = self._trim_large_entries(params)
301+
LOGGER.debug("%s %s %s", command_info[0], url, str(trimmed))
300302
return self._request(command_info[0], url, body=data)
301303

302304
def _request(self, method, url, body=None):
@@ -310,7 +312,6 @@ def _request(self, method, url, body=None):
310312
:Returns:
311313
A dictionary with the server's parsed JSON response.
312314
"""
313-
LOGGER.debug("%s %s %s", method, url, body)
314315
parsed_url = parse.urlparse(url)
315316
headers = self.get_remote_connection_headers(parsed_url, self.keep_alive)
316317
response = None
@@ -360,3 +361,21 @@ def close(self):
360361
"""Clean up resources when finished with the remote_connection."""
361362
if hasattr(self, "_conn"):
362363
self._conn.clear()
364+
365+
def _trim_large_entries(self, input_dict, max_length=100):
366+
"""Truncate string values in a dictionary if they exceed max_length.
367+
368+
:param dict: Dictionary with potentially large values
369+
:param max_length: Maximum allowed length of string values
370+
:return: Dictionary with truncated string values
371+
"""
372+
output_dictionary = {}
373+
for key, value in input_dict.items():
374+
if isinstance(value, dict):
375+
output_dictionary[key] = self._trim_large_entries(value, max_length)
376+
elif isinstance(value, str) and len(value) > max_length:
377+
output_dictionary[key] = value[:max_length] + "..."
378+
else:
379+
output_dictionary[key] = value
380+
381+
return output_dictionary

0 commit comments

Comments
 (0)