首页 > 解决方案 > 子记录器的默认设置(日志处理程序、日志级别、日志格式)是什么?

问题描述

当我使用创建子记录器logging.getLogger(__name__)时,它是否具有默认的日志处理程序、日志级别、日志格式?

标签: pythonpython-3.xpython-logging

解决方案


log = logging.getLogger(__name__)
print(log.__dict__)  # this gives attributes dictionary

输出:

{'filters': [], 'name': '__main__', 'level': 0, 'parent': <RootLogger root (WARNING)>, 'propagate': True, 'handlers': [], 'disabled': False, '_cache': {}, 'manager': <logging.Manager object at 0x000001ECCF434520>}

print('value of level attribute (i.e. log level) is: ',log.__getattribute__('level'))  # this gives value of individual attributes

输出:

value of level attribute (i.e. log level) is: 0 这里的日志级别0代表NOTSET

检查https://docs.python.org/3/library/logging.html了解详细信息。


推荐阅读