python logging.Formatter定制
2014-07-01 20:02
183 查看
需要实现在打印 WARN, ERROR, CRITICAL的log时显示函数/方法名和行号,在INFO级不显示
import logging def AltCustomFormatter(logging.Formatter): def __init__(self, fmt=None, datefmt=None): super(AltCustomFormatter, self).__init__(fmt, datefmt) def format(self, record): # 如果你添加了多个handler,你会发现我们的定制消息被重复了多次, # 我们在record里设置一个marker来避免 if record.levelno > logging.INFO and not hasattr(record, 'is_custom'): record.msg = "[%s, %s, %s] %s" % (record.filename, record.lineno, record.funcName, record.msg) record.is_custom = True return super(AltCustomFormatter, self).format(record)
相关文章推荐
- Python Logging模块-Logger,Handler,Formatter
- 定制Python的交互提示符
- Python logging RotatingFileHandler bug
- Python标准模块logging
- apache+python中对logging模块的使用问题
- Python logging日志组织方式
- python logging 模块
- python logging模块
- python 的日志logging模块学习
- python 的日志logging模块学习
- Python logging RotatingFileHandler bug
- python logging usage
- vm定制安装redhat-server5.1和安装python2.7.1
- PyCon 2011 - Hidden Treasures of the Python Standard Library - logging日志处理
- Python模块学习 ---- logging 日志记录(一)
- 使用Python的logging.config
- python logging 日志
- 用zeromq的PUB/SUB网络模型扩充python logging
- python logging (python log 日志详细)
- Python的logging.config