4

My LOGGING directive in settings is set to:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'default': {
            'format': '[%(asctime)s] %(levelname)s::(%(process)d %(thread)d)::%(module)s - %(message)s'
        },
    },
    'handlers': {
        'file_handler': {
            'level': 'DEBUG',
            'formatter':'default',
            'class': 'logging.TimedRotatingFileHandler',
            'filename':'Project_log',
            'when':'midnight',
            'interval':1
        },
    },
    'loggers': {
        'django.request': {
            'handlers': ['file_handler'],
            'level': 'DEBUG',
            'propagate': True,
        },
    }
}

The class of the handler is set to logging.HandlerName as per the docs example: https://docs.djangoproject.com/en/dev/topics/logging/

But I receive the following error:

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/config.py", line 776, in dictConfig
    dictConfigClass(config).configure()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/config.py",     line 575, in configure
'%r: %s' % (name, e))
ValueError: Unable to configure handler 'file_handler': Cannot resolve 'logging.TimedRotatingFileHandler': No module named TimedRotatingFileHandler

1 Answer 1

10

You'll have to write,

logging.handlers.TimedRotatingFileHandler

as the TimedRotatingFileHandler is part of the handlers package of logging.

Sign up to request clarification or add additional context in comments.

2 Comments

I just checked in ipython which is awesome if you just need to find out what exactely you need to import
It should be logging.handlers.TimedRotatingFileHandler

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.