Skip to content

Commit

Permalink
Add image request logging
Browse files Browse the repository at this point in the history
  • Loading branch information
F33RNI committed Oct 8, 2023
1 parent 017e9c1 commit 3108a5a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions QueueHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,24 @@ def _collect_data(self, request_response: RequestResponseContainer, log_request=
if log_request:
request_str_to_format = self.config["data_collecting"]["request_format"].replace("\\n", "\n") \
.replace("\\t", "\t").replace("\\r", "\r")

# Log image
try:
if request_response.image_url:
logging.info("Downloading user image")
image_request = base64.b64encode(requests.get(request_response.image_url,
timeout=120).content).decode("utf-8")
log_file.write(request_str_to_format.format(request_response.request_timestamp,
request_response.id,
request_response.user["user_name"],
request_response.user["user_id"],
RequestResponseContainer
.REQUEST_NAMES[request_response.request_type],
image_request))
except Exception as e:
logging.warning("Error logging image request!", exc_info=e)

# Log text
log_file.write(request_str_to_format.format(request_response.request_timestamp,
request_response.id,
request_response.user["user_name"],
Expand Down

0 comments on commit 3108a5a

Please sign in to comment.