在python中配置root记录器 [英] Configuring root logger in python
本文介绍了在python中配置root记录器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Django设置中具有以下日志记录配置.
I have the following logging configuration in in my Django settings.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format':
'%(levelname)s|%(asctime)s|%(name)s>> %(message)s',
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose',
}
},
'loggers': {
'': {
'handlers': ['console'],
'level': 'ERROR',
'propagate': True,
},
'apps': {
'handlers': ['console'],
'level': 'DEBUG',
},
}
}
使用此配置,我希望我的应用"以调试级别记录,而其他模块仅记录ERROR及以上级别.但是我看到其他模块的调试消息.我该如何解决?
With this configuration I expect my 'apps' to log at DEBUG level and any other modules to log only ERROR and above. But I see DEBUG messages from other modules. How do I fix it?
推荐答案
您是否在 LOGGING ['loggers']
中使用空字符串键来匹配根记录器?如果是这样,您可以尝试使用此方法.
Are you using an empty string key in LOGGING['loggers']
to match the root logger? If so, you could try this instead.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format':
'%(levelname)s|%(asctime)s|%(name)s>> %(message)s',
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose',
}
},
'loggers': {
'apps': {
'handlers': ['console'],
'level': 'DEBUG',
}
},
'root': {
'handlers': ['console'],
'level': 'ERROR'
}
}
这篇关于在python中配置root记录器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文