Skip to content

Commit

Permalink
Guard expensive debug logging with isEnabledFor (#358)
Browse files Browse the repository at this point in the history
Note that update_query rebuilds the whole query string
every time so it would be a bit cleaner to call it once,
however its probably not worth optimizing if its only
going to be called when debug is on now
  • Loading branch information
bdraco authored Sep 29, 2024
1 parent b092960 commit ac8c340
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/synology_dsm/synology_dsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,15 @@ async def _execute_request(
url_encoded, timeout=self._aiohttp_timeout, **kwargs
)

# mask sesitiv parameters
response_url = response.url # pylint: disable=E0606
for param in SENSITIV_PARAMS:
if params is not None and params.get(param):
response_url = response_url.update_query({param: "*********"})
self._debuglog("Request url: " + str(response_url))
self._debuglog("Response status_code: " + str(response.status))
self._debuglog("Response headers: " + str(dict(response.headers)))
# mask sesitive parameters
if _LOGGER.isEnabledFor(logging.DEBUG):
response_url = response.url # pylint: disable=E0606
for param in SENSITIV_PARAMS:
if params is not None and params.get(param):
response_url = response_url.update_query({param: "*********"})
self._debuglog("Request url: " + str(response_url))
self._debuglog("Response status_code: " + str(response.status))
self._debuglog("Response headers: " + str(dict(response.headers)))

if response.status == 200:
# We got a DSM response
Expand Down

0 comments on commit ac8c340

Please sign in to comment.