util.py 文件源码

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

项目:exchangelib 作者: ecederstrand 项目源码 文件源码
def emit(self, record):
        """Pretty-print and syntax highlight a log statement if all these conditions are met:
           * This is a DEBUG message
           * We're outputting to a terminal
           * The log message args is a dict containing keys starting with 'xml_' and values as bytes
        """
        if record.levelno == logging.DEBUG and self.is_tty() and isinstance(record.args, dict):
            for key, value in record.args.items():
                if not key.startswith('xml_'):
                    continue
                if not isinstance(value, bytes):
                    continue
                if not is_xml(value[:10].decode('utf-8', errors='ignore')):
                    continue
                try:
                    if PY2:
                        record.args[key] = self.highlight_xml(self.prettify_xml(value)).encode('utf-8')
                    else:
                        record.args[key] = self.highlight_xml(self.prettify_xml(value))
                except Exception:
                    # Something bad happened, but we don't want to crash the program just because logging failed
                    pass
        return super(PrettyXmlHandler, self).emit(record)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号