[Django]-ValueError: unable to configure handler 'loggers'

3👍

The structure of the LOGGING dictionary got mixed up. The loggers are now an element of the handlers, but should have an independent entry, like:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        # …
    },
    'handlers': {
        # …
    },
    'loggers': {
        # …
    },
}

So in this case it looks like:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': "[%(asctime)s] %(levelname)s [%(filename)s:%(lineno)s] %(message)s",
            'datefmt': "%Y/%b/%d %H:%M:%S"
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        },
    },
    'handlers': {
        'django': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': os.path.join(str(LOG_PATH), 'django.log'),
            'maxBytes': (1024 * 1024 * 10),
            'backupCount': 10,
            'formatter': 'verbose',
        },
        'user': {
            'level': 'INFO',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': os.path.join(str(LOG_PATH), 'user.log'),
            'maxBytes': 1024 * 1024 * 10,
            'backupCount': 10,
            'formatter': 'verbose',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['django', 'console'],
            'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG'),
        },
        'user': {
            'handlers': ['user', 'console'],
            'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
        },
    },

}

Leave a comment