so I have a strange error where before and after operations are not working. They previously wrote to the requests.log file, but now that is not working, AND regular print statements to the console are not working and I have no idea why:
# function to handle bson type returned by mongodb
# taken from https://stackoverflow.com/a/18405626
def parse_json(data):
return json.loads(json_util.dumps(data))
app = flask.Flask(__name__)
api = Api(app)
#we will be logging the API end point that was accessed, the time it was accessed, and how long it took to address the request
#all logging will be to a local file, requests.log.
@app.before_request
def start_timer():
g.start = time.time()
@app.after_request
def log_request(response):
now = time.time()
duration = round(now - g.start, 2)
print(response.get_data()) #not working
f = open("requests.log", "a+")
f.write("testing") #also not working
f.write("The following request took ({}) seconds".format(duration)) #not working
f.write("\n")
f.close()
print("dhefei") #not working
app.logger.info('Processing default request') #not working
print(request.url, request.remote_addr,file=sys.stderr)
return response
Any print statements outside of these operations do work.