找不到记录器“myapp.lib”的处理程序 [英] No handlers could be found for logger "myapp.lib"

查看:95
本文介绍了找不到记录器“myapp.lib”的处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚升级到Django 1.3,它带有自己的日志记录模块。我设置了日志记录,当Apache / mod_wsgi访问模块时它正在工作。但是当我使用django shell时,Logging不起作用 - 我总是收到臭名昭着的错误在shell上工作时,没有找到记录器'myapp.lib'的处理程序。 p>

这是我的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆