user647790
user647790

Reputation: 317

No handlers could be found for logger "myapp.lib"

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")

Upvotes: 1

Views: 6597

Answers (1)

dgel
dgel

Reputation: 16796

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.

Upvotes: 1

Related Questions