logging.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码
def format(self, record):

        # Save the original format configured by the user
        # when the logger formatter was instantiated
        format_orig = self._fmt

        # Replace the original format with one customized by logging level
        if record.levelno == logging.DEBUG:
            self._fmt = MyFormatter.timestamp + " " + MyFormatter.debug_char + " " + MyFormatter.message

        elif record.levelno == logging.INFO:
            self._fmt = MyFormatter.timestamp + " " + MyFormatter.info_char + " " + MyFormatter.message

        elif record.levelno == logging._levelNames["SUCCESS"]:
            self._fmt = MyFormatter.timestamp + " " + MyFormatter.success_char + " " + MyFormatter.message

        elif record.levelno == logging._levelNames["START"]:
            self._fmt = MyFormatter.timestamp + " " + MyFormatter.start_char + " " + MyFormatter.message

        elif record.levelno == logging.WARNING:
            self._fmt = MyFormatter.timestamp + " " + MyFormatter.warning_char + " " + MyFormatter.message

        elif record.levelno == logging.ERROR:
            self._fmt = MyFormatter.timestamp + " " + MyFormatter.error_char + " " + MyFormatter.message

        # Call the original formatter class to do the grunt work
        result = logging.Formatter.format(self, record)

        # Restore the original format configured by the user
        self._fmt = format_orig

        return result

# -----------------------------------------------------------------
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号