找不到记录器“myapp.lib”的处理程序 [英] No handlers could be found for logger "myapp.lib"
本文介绍了找不到记录器“myapp.lib”的处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的settings.py的日志记录部分:
LOGGING = {
'version':1,
'disable_existing_loggers':True,
'formatters':{
'simple':{
'format':'% (levelname)s%(message)s'
},
},
'handlers':{
'file':{
'class'
'form'''''''''$'$'''''''''''' b $ b'backupCount':'5'
},
'console':{
'level':'DEBUG',
'class':'logging.StreamHandler' ,
'formatter':'simple'
}
},
'loggers':{
'myapp.lib':{
'handlers':['file' ,'console',],
'level':'INFO',
},
}
}
这是导致错误的Python代码:
导入日志记录
l = logging.getLogger(__ name__)
l.warn(foo)
解决方案
要从django shell登录,您需要运行:
导入日志记录
l = logging.getLogger('myapp.lib')
l.warn(foo)
__ name __
在shell中 __ main __
I just upgraded to Django 1.3 which brings it's own logging module. I did set up logging and it is working when the modules are accessed by Apache/mod_wsgi. But when I am working with the django shell, Logging does not work - I always get the infamous error "No handlers could be found for logger 'myapp.lib'" when working on the shell.
This is the logging-part of my settings.py:
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'file': {
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'simple',
'filename': '/var/log/myapp.log',
'maxBytes': '4096',
'backupCount': '5'
},
'console': {
'level':'DEBUG',
'class':'logging.StreamHandler',
'formatter': 'simple'
}
},
'loggers': {
'myapp.lib': {
'handlers': ['file', 'console',],
'level': 'INFO',
},
}
}
And this is the Python code causing the error:
import logging
l=logging.getLogger(__name__)
l.warn("foo")
解决方案
To log from the django shell you would need to run:
import logging
l=logging.getLogger('myapp.lib')
l.warn("foo")
__name__
is __main__
at the shell.
这篇关于找不到记录器“myapp.lib”的处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文