没有合适的资源?快使用搜索试试~ 我知道了~
详解Python logging调用Logger.info方法的处理过程
1 下载量 113 浏览量
2021-01-21
18:35:24
上传
评论
收藏 136KB PDF 举报
温馨提示
本次分析一下Logger.info的流程 1. Logger.info源码: def info(self, msg, *args, **kwargs): Log 'msg % args' with severity 'INFO'. To pass exception information, use the keyword argument exc_info with a true value, e.g. logger.info(Houston, we have a %s, interesting problem, exc_info=1)
资源推荐
资源详情
资源评论





























详解详解Python logging调用调用Logger.info方法的处理过程方法的处理过程
本次分析一下Logger.info的流程
1. Logger.info源码源码:
def info(self, msg, *args, **kwargs):
"""
Log 'msg % args' with severity 'INFO'.
To pass exception information, use the keyword argument exc_info with
a true value, e.g.
logger.info("Houston, we have a %s", "interesting problem", exc_info=1)
"""
if self.isEnabledFor(INFO):
self._log(INFO, msg, args, **kwargs)
注释中反应了可以通过 msg和不定参数args来进行日志的格式化。
真实的调用为:_log方法:
2. Logger._log方法方法:
def _log(self, level, msg, args, exc_info=None, extra=None, stack_info=False):
"""
Low-level logging routine which creates a LogRecord and then calls
all the handlers of this logger to handle the record.
"""
sinfo = None
if _srcfile:
#IronPython doesn't track Python frames, so findCaller raises an
#exception on some versions of IronPython. We trap it here so that
#IronPython can use logging.
try:
fn, lno, func, sinfo = self.findCaller(stack_info)
except ValueError: # pragma: no cover
fn, lno, func = "(unknown file)", 0, "(unknown function)"
else: # pragma: no cover
fn, lno, func = "(unknown file)", 0, "(unknown function)"
if exc_info:
if isinstance(exc_info, BaseException):
exc_info = (type(exc_info), exc_info, exc_info.__traceback__)
elif not isinstance(exc_info, tuple):
exc_info = sys.exc_info()
record = self.makeRecord(self.name, level, fn, lno, msg, args,
exc_info, func, extra, sinfo)
self.handle(record)
最后两行:
生成日志记录:
record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra, sinfo)
处理日志记录
self.handle(record)
2 生成日志记录:
def makeRecord(self, name, level, fn, lno, msg, args, exc_info,
func=None, extra=None, sinfo=None):
"""
A factory method which can be overridden in subclasses to create
specialized LogRecords.
"""
rv = _logRecordFactory(name, level, fn, lno, msg, args, exc_info, func,
sinfo)
if extra is not None:
for key in extra:
if (key in ["message", "asctime"]) or (key in rv.__dict__):
raise KeyError("Attempt to overwrite %r in LogRecord" % key)
资源评论


weixin_38684976
- 粉丝: 5
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 互联网+小学英语作业的初探.docx
- 化工行业信息化建设方案.pdf
- 太阳能光伏发电系统照明系统设计自动化专业毕业设计.doc
- ARM处理器LCD控制及触摸屏接口设计方案.doc
- 《数据库原理及应用》考试大纲.doc
- 软件项目管理—如何进行项目估算.docx
- 基于89C51单片机的数字钟方案设计书(2).doc
- 中国应用交付网络市场分析报告-行业竞争现状与前景评估预测.docx
- 分层互动教学模式在中职计算机应用基础课程中的探究.docx
- 计算机科学与工程项目个人简历.doc
- 软件工程课后习题答案.doc
- authorware课程设计方案5.doc
- 基于计算机辅助语料库对中美研究者医学论文功能词使用的对比分析.docx
- VB-ACCESS的工资管理系统本科生.doc
- 工程项目管理材料封样要求.doc
- 基于应用型人才培养的大学计算机课程改革研究.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
