Logging in python + mod_wsgi app

[亡魂溺海] 提交于 2019-12-07 17:04:04

问题


I've deployed a python flask app on an apache server. Here is my abc.conf file:

WSGIDaemonProcess voting_app threads=5
WSGIScriptAlias /election /var/www/voting_app/voting.wsgi

LogLevel info
ErrorLog "/var/www/voting_app/error.log"
CustomLog "/var/www/voting_app/access.log" combined

<Directory /var/www/voting_app>
    WSGIProcessGroup voting_app
    WSGIApplicationGroup %{GLOBAL}
    Order deny,allow
    Allow from all
</Directory>

To check debugging I made a syntax error in my application. On restarting the server, I am getting a 500 server error but I cant see the details of the error anywhere. I checked the two files I added as logs - they're completely blank. So are the log files in /var/log/apache2. What am I missing here?


回答1:


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/




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/12385915/logging-in-python-mod-wsgi-app

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