添加自定义logginng日志等级

2020-01-03  本文已影响0人  zhu733756

import logging

logging.TRACE = 25

logging.addLevelName(logging.TRACE, "TRACE")

def __log_trace(self, message, *args, **kwargs):

    if self.isEnabledFor(logging.TRACE):

        self._log(logging.TRACE, message, args, **kwargs)

logging.basicConfig(

    format='%(asctime)s %(filename)s [line:%(lineno)d] %(levelname)s: %(message)s', 

    datefmt='%Y-%m-%d %H:%M:%S', 

    level=logging.DEBUG

)

logging.Logger.trace = __log_trace

log = logging.getLogger('qqq')

log.setLevel(logging.DEBUG)

log.trace('asdf')

上一篇 下一篇

猜你喜欢

热点阅读