Easy application logging/debugging with nginx, uwsgi, flask?
- The part where you create handlers, add to loggers etc. should be in the
if __name__ == '__main__'
clause, i.e. your main entry point. I assume that would berun.py
. - I'm not sure I can answer this - it depends on what you want. I'd advise looking at the logging tutorial to see the various options available.
- I don't believe you need to change anything at the
nginx
level.
Update: You might want to have an exception clause that covers uncaught exceptions, e.g.
if __name__ == '__main__': try: app.run(debug=True) except Exception: app.logger.exception('Failed')
which should write the traceback of any exception which occurred in app.run()
to the log.
I know that this is a VERY old post, but I ran into the issue now, and it took me a bit to find the solution. Flask sends errors to the server. I was running Gunicorn with an upstart script on Ubuntu 14.04 LTS, and the place where I found the error logs was as follows:
/var/log/upstart/myapp.log
http://docs.gunicorn.org/en/stable/deploy.html#upstart
Just in case some other poor soul ends up in this situation.