Logging in python + mod_wsgi app

[亡魂溺海] 提交于 2019-12-06 02:20:11

When running Flask in a production setting, rather than with the built in development server, it will convert application exceptions into HTTP 500 responses but not log anything. So what you are seeing is normal.

If you are the only one viewing the site, you can enable debug mode temporarily like would be done automatically with the development server. For how to do this see:

http://flask.pocoo.org/docs/quickstart/#debug-mode

Specifically:

app.debug = True

where 'app' is the Flask class instance.

This will cause details of errors to be shown in the browser making the request.

On a true production system you obviously shouldn't be using that so in that case you should set up Flask to log such application errors. For that see:

http://flask.pocoo.org/docs/errorhandling/

Did you check if Apache has write access in the voting_app directory?

If you're running on Ubuntu 11.10 or later then you may be getting bitten by this bug. Apparently when the Python subprocess crashes it should be dumping the stacktrace to the Apache log but it fails to do so in some cases. That bug report refers to another bug report with the maintainers of mod_wsgi. The reporter made some advances in debugging the issue, but got stuck way back in 2013, and AFAICT progress has since ceased.

For now at least you should just follow Graham Dumpleton's answer and configure a logger for your application as described by Flask's documentation. You may want to wrap that logger configuration code in a try-except block in case the initial setup fails.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!