I have below part of Python
code extraction.py
where i have lot of print
statements and there are other logs generated from REST API
. I want to create logfile with date and time prefix attached with the log file for example log_yyyy-MM-dd-hhminss to track all the logs from my Python code. This will help to track daily logs from my Python code.
import requests
import json
import shutil
import time
import gzip
import os
extraction request:
if status_code == 202:
requestUrl = r2.headers["location"]
print('Extraction is not complete, we shall poll the location URL:')
print(str(requestUrl))
requestHeaders = {
"Prefer": "respond-async",
"Content-Type": "application/json",
"Authorization": "token " + token
}
while (status_code == 202):
print('As we received a 202, we wait 30 seconds, then poll again (until we receive a 200)')
time.sleep(30)
r3 = requests.get(requestUrl, headers=requestHeaders)
status_code = r3.status_code
print('HTTP status of the response: ' + str(status_code))