modify logger _response_hook to avoid printing streamed results
@@ -172,7 +172,10 @@ class BaseQuery:
return self.__class__(*args, **kwargs)
def _response_hook(self, response, *args, **kwargs):
- # Log request at INFO severity
+ loglevel = log.getEffectiveLevel()
+
+ if loglevel >= 10:
+ # Log request at DEBUG severity
request_hdrs = '\n'.join(f'{k}: {v}' for k, v in response.request.headers.items())
request_log = textwrap.indent(
f"-----------------------------------------\n"
@@ -182,8 +185,17 @@ class BaseQuery:
f"{response.request.body}\n"
f"-----------------------------------------", '\t')
log.debug(f"HTTP request\n{request_log}")
- # Log response at DEBUG severity
+ if loglevel >= 5:
+ # Log response at super-DEBUG severity
response_hdrs = '\n'.join(f'{k}: {v}' for k, v in response.headers.items())
+ if kwargs.get('stream'):
+ response_log = textwrap.indent(
+ f"-----------------------------------------\n"
+ f"{response.status_code} {response.reason} {response.url}\n"
+ f"{response_hdrs}\n"
+ "Streaming Data\n"
+ f"-----------------------------------------", '\t')
+ else:
response_log = textwrap.indent(
f"-----------------------------------------\n"
f"{response.status_code} {response.reason} {response.url}\n"
@@ -387,6 +399,9 @@ class BaseQuery:
blocksize = astropy.utils.data.conf.download_block_size
+ log.debug(f"Downloading URL {url} to {local_filepath} with size {length} "
+ f"by blocks of {blocksize}")
+
bytes_read = 0
# Only show progress bar if logging level is INFO or lower.
