I have added a custom loggin to my django project but it isn't working

I have added this code to my settings.py, but its not working. Django defualt logging works perfectly fine, debug is True in my settings and i've created logs folder manually.

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'file_logging': {
            'format': '{levelname} / {levelno} - {asctime} --- {pathname} in {lineno} --- {process:d} {thread:d} -- {message}',
            'style': '{'
        },
        'email_logging': {
            'format': '{levelname} at {asctime} --- {pathname} in {lineno} -- {message}',
            'style': '{'
        },
    },
    'filters': {
        'debug_true_required': {
            '()': 'django.utils.log.RequireDebugTrue'
        }
    },
    'handlers': {
        'full_handler': {
            'level': 'INFO',
            'class': 'logging.FileHandler',
            'filename': 'logs/full.log',
            'formatter': 'file_logging',
        },
        'critical_handler': {
            'level': 'CRITICAL',
            'class': 'logging.FileHandler',
            'filename': 'logs/critical.log',
            'formatter': 'file_logging',
        },
        'error_handler': {
            'level': 'ERROR',
            'filters': ['debug_true_required',],
            'class': 'logging.FileHandler',
            'filename': 'logs/error.log',
            'formatter': 'file_logging',
        },
        'critical_email_handler': {
            'level': 'CRITICAL',
            'class': 'django.utils.log.AdminEmailHandler',
            'formatter': 'email_logging',
        },
        'error_email_handler': {
            'level': 'ERROR',
            'filters': ['debug_true_required',],
            'class': 'django.utils.log.AdminEmailHandler',
            'formatter': 'email_logging',
        },
    },
    'loggers': {
        'file_logger': {
            'handlers': ['full_handler', 'critical_handler', 'error_handler'],
            'level': 'INFO',
            'propagate': True
        },
        'email_logger': {
            'handlers': ['critical_email_handler', 'error_email_handler'],
            'level': 'ERROR',
            'propagate': True
        },
    }
}

I tried recreating logs folder again, but it didn't work, then i tried changing 'propagate': False to True but it didn't work again, and also i tried logging manualy with this code, which works perfectly fine, and the logs saved correctly in my logging files.

logger = logging.getLogger('file_logger')
logger.info("This is a test log message.")

logger = logging.getLogger('email_logger')
logger.critical("This is a test critical message.")
Вернуться на верх