flask 添加日志
- def add_error_handler(app):
- for exception in default_exceptions:
- app.register_error_handler(exception, error_handler)
- app.register_error_handler(Exception, error_handler)
- def error_handler(error):
- description = error.get_description(request.environ) \
- if hasattr(error, 'get_description') else None
- exc_type, exc_value, exc_traceback = sys.exc_info()
- traceback.print_exception(exc_type, exc_value, exc_traceback)
- current_app.logger.error(
- """
- Request: {method} {path}
- IP: {ip}
- User: {user}
- Agent: {agent_platform} | {agent_browser} {agent_browser_version}
- Raw Agent: {agent}
- Description: {description}
- """.format(
- method=request.method,
- path=request.path,
- ip=request.remote_addr,
- agent_platform=request.user_agent.platform,
- agent_browser=request.user_agent.browser,
- agent_browser_version=request.user_agent.version,
- agent=request.user_agent.string,
- user=g.user if hasattr(g, 'user') else None,
- description=description,
- ), exc_info=exc_traceback
- )
- if isinstance(error, HTTPException):
- code = error.code
- if code == 404:
- return make_response(jsonify({'code': 404, 'data': {}, 'msg': 'page not found'}), code)
- else:
- """其他HTTP异常处理暂未定义"""
- pass
- else:
- current_app.logger.error('Internal Server Error')
- return make_response(jsonify({'code': 500, 'data': {}, 'msg': 'Internal Server Error'}))
- app = Flask(__name__)
- add_error_handler(app)
flask 添加日志的更多相关文章
- Flask--(项目准备)--添加日志
日志:记录程序运行的状态,在manage.py同级目录下创建logs文件夹 定义日志文件: import logging from logging.handlers import RotatingFi ...
- logging 为全局的日志工具对象添加日志记录器
def log_file(LEVEL_NAME): # 设置日志的记录等级,常见的有四种,大小关系如下,DEBUG < INFO < WARNING <ERROR # 一旦设置级别, ...
- 测试平台系列(3) 给Hello World添加日志
给Hello World添加日志 回顾 通过上篇内容,我们已经使用「Flask」完成了我们的第一个接口.我们可以看到,使用「Flask」来编写接口是十分简单的.那么接下来,我们丰富一下上面的例子. 需 ...
- ASP.NET Core 添加日志NLog
1.在Nuget上搜索 NLog.Extensions.Logging 安装最新版 2.添加日志配置文件,在项目指定目录下添加配置文件nlog.config,内容添加如下: <?xml vers ...
- (译)Windsor入门教程---第五部分 添加日志功能
介绍 现在我们已经有了基础的框架了,是时候添加内容了,那么我们首先应该考虑的就是在应用程序中添加日志功能.我们会使用Windsor来配置,在这一部分,你将学习Windsor之外的其他功能. L ...
- python web开发-flask中日志的使用
Flask使用日志记录的方式: 初始化flask应用实例 在flask中使用logger,需要初始化一个flask的应用 app = Flask(__name__) 2. 调用logger 直接调用l ...
- net core中动态给log4net添加日志类型
private static object m_Lock = new object(); /// <summary> /// 根据类型获取对应的日志操作类 /// </summary ...
- ThinkPHP执行调用存储过程添加日志
本文出至:新太潮流网络博客 //PHP代码部分 /** * [LogAdd 操作日志] * @param [string] $userid [用户的ID] * @param [string] $typ ...
- SSIS教程:创建简单的ETL包 -- 3. 添加日志(Adding Logging)
Microsoft Integration Services 包含日志记录功能,可通过提供任务和容器事件跟踪监控包执行情况以及进行故障排除. 日志记录功能非常灵活,可以在包级别或在包中的各个任务和容器 ...
随机推荐
- 学习di'z地址
Swift学习地址https://numbbbbb.gitbooks.io/-the-swift-programming-language-/content/ http://www.oschina.n ...
- nodejs gulp less编辑
nodejs 下载地址:http://pan.baidu.com/s/1bnz2oPp 提取密码:0mip 1.最简单的编译less 在安装好nodejs后,cmd 进入控制台 安装 lessc : ...
- ROS 使用自带和usb摄像头获取图像
笔记本自带的摄像头的设备号一般为/dev/video0 第一步:安装Webcam 驱动 $ sudo apt-get install git-core $ cd ~/catkin_ws/src $ g ...
- Hibernate 检索方式
概述 •Hibernate 提供了以下几种检索对象的方式 –导航对象图检索方式: 根据已经加载的对象导航到其他对象 –OID 检索方式: 按照对象的 OID 来检索对象 –HQL 检索方式: 使用 ...
- [转]Android,Yocto,Meego构建系统的区别
http://m.blog.csdn.net/blog/sonach_tjsd/6647829
- jetty启动不能保存
主要原因是jetty缓存的静态页面不能被修改.只需要在web.xml文件中配置如下: <servlet> <!-- Override init parameter to avo ...
- mysql之存储过程
一.存储过程 迄今为止,使用的大多数 SQL语句都是针对一个或多个表的单条语句.并非所有操作都这么简单,经常会有一个完整的操作需要多条语句才能完成.例如,考虑以下的情形. 1. ...
- realestate.cei.gov.cn
using AnfleCrawler.Common; using System; using System.Collections.Concurrent; using System.Collectio ...
- Wireshark找不到网络接口问题
Wireshark找不到网络接口问题 在运行Wireshark工具抓包时,需要有管理员用户权限.如果是普通用户启动的话,将会提示找不到网络接口.
- UE4 编译后 不能正常使用Open Level 打开关卡解决方案:Open Level Blueprint Node not workin
配置DefaultEditor.ini 文件 [AllMaps] +Map=/关卡文件路径 参考文献: https://answers.unrealengine.com/questions/141 ...