禁用请求记录到烧瓶中的控制台

时间:2018-12-27 19:28:46

标签: python logging flask

我在这里尝试了所有操作:Disable console messages in Flask 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放在所有这些函数中而不是在代码中,它也会将它们打印到控制台。我真的很笨有人对此有可行的解决方案吗?

0 个答案:

没有答案