Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django logging with dictConfig cannot find "logging" module

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
like image 878
WilHall Avatar asked Dec 27 '22 16:12

WilHall


1 Answers

You'll have to write,

logging.handlers.TimedRotatingFileHandler

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

like image 198
BergmannF Avatar answered Dec 30 '22 09:12

BergmannF