我试图使用app.logger.error('')
在decorator函数中记录一个错误,但它根本不起作用。此外,我无法很好地调试,只能看到来自http客户端的响应:
(我用的是nginx+uwsgi+烧瓶)
HTTP/1.1 502 Bad Gateway
Server: nginx
Date: Sun, 12 Aug 2012 15:45:09 GMT
Content-Type: text/html
Content-Length: 14
Connection: keep-alive
一切都很好,不用排队:app.logger.error('panic !!!')
def mydecorator():
def decorator(f):
def wrapped_function(*args, **kwargs):
try:
ip = Mytable.query.filter_by(ip=request.remote_addr).first()
except:
app.logger.error('panic !!!')
else:
dootherthing()
resp = make_response(f(*args, **kwargs))
h = resp.headers
h['add-this-header'] = ":)"
return resp
return update_wrapper(wrapped_function, f)
return decorator
似乎是断章取义之类的。
是否在您发布的脚本中的任何地方定义了
app
?另外,为了帮助调试,在测试时应该考虑对debug mode使用
run()
方法。实际上,decorator无法检测上下文外的应用程序实例,我使用当前的应用程序解决这个问题:
1.导入方法:
from flask import current_app
第二。将任何应用程序类附加到当前应用程序:
current_app.logger.error('panic !!!')
相关问题 更多 >
编程相关推荐