flask 服务关闭控制台日志打印
就是不想看到这些日志要如何设置
3条回答 默认 最新
- CSDN专家-showbo 2022-08-04 11:14关注
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
python flask 如何记录500错误日志-编程语言-CSDN问答 CSDN问答为您找到python flask 如何记录500错误日志相关问题答案,如果想了解更多关于python flask 如何记录500错误日志 python、flask、后端、 技术问题等相关问答,请访问CSDN问答。 https://ask.csdn.net/questions/7764820解决 1无用
悬赏问题
- ¥15 YoloV5 第三方库的版本对照问题
- ¥15 请完成下列相关问题!
- ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
- ¥15 求daily translation(DT)偏差订正方法的代码
- ¥15 js调用html页面需要隐藏某个按钮
- ¥15 ads仿真结果在圆图上是怎么读数的
- ¥20 Cotex M3的调试和程序执行方式是什么样的?
- ¥20 java项目连接sqlserver时报ssl相关错误
- ¥15 一道python难题3
- ¥15 牛顿斯科特系数表表示