Easy application logging/debugging with nginx, uwsgi, flask?

后端 未结 3 791
被撕碎了的回忆
被撕碎了的回忆 2021-02-05 04:06

I\'m not looking to turn on the dangerous debugging console, but my application is getting a 500 error and doesn\'t seem to be writing any output for me to investigate more deep

相关标签:
3条回答
  • 2021-02-05 04:32

    Set config['PROPAGATE_EXCEPTIONS'] to True when running app in production and you want tracebacks to be logged into log files. (I haven't tried with SMTP handler, though..)

    0 讨论(0)
  • 2021-02-05 04:40

    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.

    0 讨论(0)
  • 2021-02-05 04:49
    1. 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 be run.py.
    2. 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.
    3. 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.

    0 讨论(0)
提交回复
热议问题