【发布时间】:2019-05-25 18:30:36
【问题描述】:
我在这里尝试了一切:Disable console messages in Flask server 但我唯一能做到的就是禁用 *starting server。
我在 Serving.py 的 werkzeug 模块中发现了它的功能:
def log_request(self, code='-', size='-'):
msg = self.requestline
code = str(code)
if termcolor:
color = termcolor.colored
if code[0] == '1': # 1xx - Informational
msg = color(msg, attrs=['bold'])
elif code[0] == '2': # 2xx - Success
msg = color(msg, color='white')
elif code == '304': # 304 - Resource Not Modified
msg = color(msg, color='cyan')
elif code[0] == '3': # 3xx - Redirection
msg = color(msg, color='green')
elif code == '404': # 404 - Resource Not Found
msg = color(msg, color='yellow')
elif code[0] == '4': # 4xx - Client Error
msg = color(msg, color='red', attrs=['bold'])
else: # 5xx, or any other response
msg = color(msg, color='magenta', attrs=['bold'])
self.log('info', '"%s" %s %s', msg, code, size)
def log(self, type, message, *args):
_log(type, '%s - - [%s] %s\n' % (self.address_string(),
self.log_date_time_string(),
message % args))
但即使将pass 放入所有这些函数而不是代码中,它也会将它们打印到控制台。我真是一头雾水。有人对此有有效的解决方案吗?
【问题讨论】:
-
为什么需要这样做?
-
我正在尝试使用控制台实时监控站点活动,但它只是向它发送垃圾邮件。即使禁用它是愚蠢的,为什么不能禁用它?
-
好吧,如果您要托管在适当的生产服务器上,您将不会获得任何日志。毕竟,它是一个开发服务器
-
但即使将 pass [...] 打印到控制台 你如何启动你的烧瓶应用程序?清空这 2 个函数应该完全禁用
127.0.0.1 - - [01/Dec/2018 00:00:00] "POST / HTTP/1.1" 200 -消息(即使这样做不是正确的方法,您应该禁用logging.getLogger('werkzeug')记录器),但是您的 WSGI 服务器或 Web 服务器仍可能发出这些消息。 -
如原帖中所述,我试图简单地禁用记录器但没有成功。我如何启动应用程序:
app = Flask(__name__) mysql = MySQL(app) socketio = SocketIO(app) if __name__ == '__main__': socketio.run(app , debug=debug, host=host, port=port)