您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

是否可以根据消息日志级别修改Python的日志记录格式?

是否可以根据消息日志级别修改Python的日志记录格式?

是的,您可以通过创建一个自定义Formatter类来做到这一点:

class MyFormatter(logging.Formatter):
    def format(self, record):
        #compute s according to record.levelno
        #for example, by setting self._fmt
        #according to the levelno, then calling
        #the superclass to do the actual formatting
        return s

然后将一个MyFormatter实例附加到您的处理程序。

python 2022/1/1 18:46:51 有305人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶