I use next code to caught uncaught exceptions in my Flask app:
@app.errorhandler(Exception)
def uncaught_exception_handler(error):
if not app.config['DEVELOPMENT']:
app.logger.error(error, exc_info=True)
else:
raise error
return 'Internal Server Error', 500
How can I add extra information about values of variables in each stack frame to my log file? It looks like cgitb
is doing desired things but it print error info to stdout or to a file and not returned it as a string. I know that it is possible to do what I want with inspect
and traceback
modules but as this is Python I think that there already exists appropriate solution for such problem.