from pathlib import Path
# Base directory of the project
BASE_DIR = Path(__file__).resolve().parent.parent

# https://www.youtube.com/watch?v=9DbOLRE6me0
# https://github.com/andyjud/django-starter

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse',
        },
    },
    'formatters': {
        'simple': {
            'format': '{levelname} {asctime:s} {name} {message}',
            'style': '{',
        },
        'verbose': {
            'format': '{levelname} {asctime:s} {module} {process:d} {thread:d} {message}',
            'style': '{',
        }
    },
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'simple',
        },
        'file': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': BASE_DIR / 'app.log',
            'formatter': 'verbose',
        },
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler',
            'filters': ['require_debug_false'],
            'formatter': 'verbose',
        },
    },
    'loggers': {
        "": {
            "level": "WARNING",
            "handlers": ["console", "file", "mail_admins"],
        },
        "django": {
            "level": "INFO",
            "handlers": ["console"],
            "propagate": False,
        },
        "django.template": {
            "level": "INFO",
            "handlers": ["file"],
            "propagate": True,
        },
    },
}