python flask 关闭请求日志

flask 服务关闭控制台日志打印
就是不想看到这些日志要如何设置

img

Flask provides a method to do this. Define an errorhandler method like this.

@app.errorhandler(500)
def handle_500_error(err_msg):
    file_handler = RotatingFileHandler('error.log', maxBytes=1024 * 1024 * 100, backupCount=20)
    file_handler.setLevel(logging.ERROR)
    formatter = logging.Formatter("\n\r%(asctime)s - %(name)s - %(levelname)s - %(message)s")
    file_handler.setFormatter(formatter)
    app.logger.addHandler(file_handler)
    data = {"page_title": "500"}
    return render_template("/cn/error/500.html",**data)
 

Whenever a view raises an exception, this method will be called and passed the exception as argument. Python logging provides exception method that is used to save full traceback of the exception.

https://stackoverflow.com/questions/14037975/how-do-i-write-flasks-excellent-debug-log-message-to-a-file-in-production

这个关闭不了,这个是后台的HTTP请求信息,不影响的

文章:Python - Flask - 日志 中也许有你想要的答案,请看下吧