使用mod_wsgi记录烧瓶错误 [英] logging flask errors with mod_wsgi

查看:57
本文介绍了使用mod_wsgi记录烧瓶错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很长一段时间以来,我一直在努力使这个工作正常进行,但是现在我真的处于机智状态.我已尝试做所有可以在SO和flask文档上找到的内容,但仍然无法通过简单的错误日志来调试应用程序.下面是粘贴的代码-

I've been trying to get this working since a long time but I'm really at my wits end now. I've tried to do everything that I could find on SO and flask documentation and still I cant a simple error log working so that I can debug my applcation. Below is the pasted code -

# main.py
from flask import Flask
import logging

app = Flask(__name__)
file_handler = logging.FileHandler(filename='/tmp/election_error.log')
file_handler.setLevel(logging.WARNING)
app.logger.addHandler(file_handler)

@app.route('/')
def hello():
   return "hello
   #missing quotes to generate error

if __name__ == "__main__":
   app.run()


#wsgi file
import sys
import logging
sys.path.insert(0, "/var/www/voting_app")
logging.basicConfig(stream=sys.stderr)
from main import app as application


# apache2 conf file
WSGIDaemonProcess voting_app threads=5
WSGIScriptAlias /election /var/www/voting_app/voting_app.wsgi

LogLevel info

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

请告诉我我要去哪里了.非常感谢.

Please tell me where I'm going wrong. Thank you so much.

推荐答案

您创建的特定错误(语法错误)将导致WSGI脚本文件无法加载到mod_wsgi中.该错误将最终存储在Apache错误日志文件中,而不是您使用日志记录模块设置的日志文件中.您是否查看过Apache错误日志文件?

The specific error you created, which was a syntax error, would have caused failure of the WSGI script file to even load in mod_wsgi. The error for this would have ended up in the Apache error log file, not the log file you are setup using the logging module. Have you looked in the Apache error log file?

对于在请求执行期间引发的异常,Flask默认情况下会将其转换为500错误页面,否则将禁止显示详细信息.您需要按照以下方式将Flask设置为以其他方式通过邮件发送或记录此类运行时异常:

For an exception raised during request execution, Flask would by default turn it into a 500 error page and otherwise supress the display of the details. You need to set up Flask to mail or log such runtime exceptions in other ways per:

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

如果出于开发目的,要在返回到浏览器的500页中显示运行时异常,则需要启用Flask调试模式.这是通过将app.debug设置为True来完成的:

If you want a runtime exception to be displayed in the 500 page returned to the browser for development purposes, you need to enable Flask debug mode. This is done by setting app.debug to be True:

http://flask.pocoo.org/docs/config/?highlight=app%20debug

您不应在面向生产系统的用户上启用调试模式.

You should not have debug mode enabled on a user facing production system.

这篇关于使用mod_wsgi记录烧瓶错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆