Skip to content

Commit 8931f46

Browse files
committed
Compute URL in log only once
1 parent 655b088 commit 8931f46

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

sonar/platform.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import datetime
3333
import json
3434
import tempfile
35+
import logging
3536
import requests
3637
import jprops
3738
from requests.exceptions import HTTPError
@@ -221,8 +222,10 @@ def __run_request(
221222
headers["Authorization"] = f"Bearer {self.__token}"
222223
if kwargs.get("with_organization", True):
223224
params["organization"] = self.organization
224-
req_type = getattr(request, "__name__", repr(request)).upper()
225-
log.debug("%s: %s", req_type, self.__urlstring(api, params))
225+
if log.get_level() >= logging.DEBUG:
226+
req_type = getattr(request, "__name__", repr(request)).upper()
227+
url = self.__urlstring(api, params)
228+
log.debug("%s: %s", req_type, url)
226229

227230
try:
228231
retry = True
@@ -237,7 +240,7 @@ def __run_request(
237240
timeout=self.http_timeout,
238241
)
239242
(retry, new_url) = _check_for_retry(r)
240-
log.debug("HTTP request took %d ms", (time.perf_counter_ns() - start) // 1000000)
243+
log.debug("%s: %s took %d ms", req_type, url, (time.perf_counter_ns() - start) // 1000000)
241244
if retry:
242245
self.url = new_url
243246
r.raise_for_status()

0 commit comments

Comments
 (0)