本文介绍了在Flask服务器中禁用控制台消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Flask服务器以独立模式运行(使用 app.run()
)。但是,我不想在控制台中有任何消息,比如 127.0.0.1 - - [15 / Feb / 2013 10 :52:22]GET /index.html HTTP / 1.1200 -
...
如何禁用详细模式?
解决方案
您可以将Werkzeug记录器的设置级别设置为ERROR,只记录错误:
$ $ p $ $ code $ import $ b $ log $ logLogger('werkzeug')
log .setLevel(logging.ERROR)
下面是OSX上的一个完整的工作示例,Python 2.7.5 ,Flask 0.10.0:
from flask import Flask
app = Flask(__ name__)
导入日志
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
@ app.route(/)
def hello():
返回Hello World!
if __name__ ==__main__:
app.run()
I have a Flask server running in standalone mode (using app.run()
). But, I don't want any messages in the console, like
127.0.0.1 - - [15/Feb/2013 10:52:22] "GET /index.html HTTP/1.1" 200 -
...
How do I disable verbose mode?
解决方案
You can set set level of the Werkzeug logger to ERROR, in that case only errors are logged:
import logging
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
Here are a full working example testet on OSX, Python 2.7.5, Flask 0.10.0:
from flask import Flask
app = Flask(__name__)
import logging
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
这篇关于在Flask服务器中禁用控制台消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!