<commit_before>"""
Django settings for odl_video project.
"""
import logging
import os
import platform
from urllib.parse import urljoin

import dj_database_url
from django.core.exceptions import ImproperlyConfigured

from odl_video.envs import (
    get_any,
    get_bool,
    get_int,
    get_key,
    get_string,
)

VERSION = "0.2.1"

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

SECRET_KEY = get_string(
    'DJANGO_SECRET_KEY',
    '<KEY>',
)

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = get_bool('DEBUG', False)

ALLOWED_HOSTS = ['*']


WEBPACK_LOADER = {
    'DEFAULT': {
        'CACHE': not DEBUG,
        'BUNDLE_DIR_NAME': 'bundles/',
        'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'),
        'POLL_INTERVAL': 0.1,
        'TIMEOUT': None,
        'IGNORE': [
            r'.+\.hot-update\.+',
            r'.+\.js\.map'
        ]
    }
}

# Request files from the webpack dev server
USE_WEBPACK_DEV_SERVER = get_bool('ODL_VIDEO_SERVICE_USE_WEBPACK_DEV_SERVER', False)
WEBPACK_DEV_SERVER_HOST = get_string('WEBPACK_DEV_SERVER_HOST', '')
WEBPACK_DEV_SERVER_PORT = get_int('WEBPACK_DEV_SERVER_PORT', 8082)


# Application definition

INSTALLED_APPS = [
    'ui.apps.UIConfig',
    'cloudsync.apps.CloudSyncConfig',
    'mail.apps.MailConfig',
    'dj_elastictranscoder',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'server_status',
    'raven.contrib.django.raven_compat',
]

SESSION_ENGINE = 'django.contrib.sessions.backends.signed_cookies'

DISABLE_WEBPACK_LOADER_STATS = get_bool("DISABLE_WEBPACK_LOADER_STATS", False)
if not DISABLE_WEBPACK_LOADER_STATS:
    INSTALLED_APPS += ('webpack_loader',)

MIDDLEWARE_CLASSES = [
    'raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

if get_bool('USE_SHIBBOLETH', False):
    # TOUCHSTONE
    MIDDLEWARE_CLASSES.append('shibboleth.middleware.ShibbolethRemoteUserMiddleware')
    SHIBBOLETH_ATTRIBUTE_MAP = {
        "EPPN": (True, "username"),
        "MAIL": (True, "email"),
        # full name is in the "DISPLAY_NAME" header,
        # but no way to parse that into first_name and last_name...
    }
    AUTHENTICATION_BACKENDS = [
        'shibboleth.backends.ShibbolethRemoteUserBackend',
    ]
    LOGIN_URL = "/Shibboleth.sso/Login"
else:
    LOGIN_URL = "/login/"

ROOT_URLCONF = 'odl_video.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'odl_video.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
# Uses DATABASE_URL to configure with sqlite default:
# For URL structure:
# https://github.com/kennethreitz/dj-database-url
DEFAULT_DATABASE_CONFIG = dj_database_url.parse(
    get_string(
        'DATABASE_URL',
        'sqlite:///{0}'.format(os.path.join(BASE_DIR, 'db.sqlite3'))
    )
)
DEFAULT_DATABASE_CONFIG['CONN_MAX_AGE'] = get_int('ODL_VIDEO_DB_CONN_MAX_AGE', 0)

if get_bool('ODL_VIDEO_DB_DISABLE_SSL', False):
    DEFAULT_DATABASE_CONFIG['OPTIONS'] = {}
else:
    DEFAULT_DATABASE_CONFIG['OPTIONS'] = {'sslmode': 'require'}

DATABASES = {
    'default': DEFAULT_DATABASE_CONFIG
}


# the full URL of the current application is mandatory
ODL_VIDEO_BASE_URL = get_string('ODL_VIDEO_BASE_URL', None)

# Celery
# http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html
REDIS_URL = get_string("REDIS_URL", None)
USE_CELERY = True
CELERY_RESULT_BACKEND = CELERY_BROKER_URL = REDIS_URL

CELERY_TASK_ALWAYS_EAGER = get_bool("CELERY_TASK_ALWAYS_EAGER", False)
CELERY_TASK_EAGER_PROPAGATES = get_bool("CELERY_TASK_EAGER_PROPAGATES", True)

CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TIMEZONE = 'UTC'
CELERY_BEAT_SCHEDULE = {
    'update-statuses': {
        'task': 'cloudsync.tasks.update_video_statuses',
        'schedule': get_int('VIDEO_STATUS_UPDATE_FREQUENCY', 60)
    },
    'watch-bucket': {
        'task': 'cloudsync.tasks.monitor_watch_bucket',
        'schedule': get_int('VIDEO_WATCH_BUCKET_FREQUENCY', 900)
    }
}

# django cache back-ends
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
        'LOCATION': 'local-in-memory-cache',
    },
    'redis': {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": CELERY_BROKER_URL,
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient"
        },
    },
}


# features flags
def get_all_config_keys():
    """Returns all the configuration keys from both environment and configuration files"""
    return list(os.environ.keys())


ODL_VIDEO_FEATURES_PREFIX = get_string('ODL_VIDEO_FEATURES_PREFIX', 'FEATURE_')
FEATURES = {
    key[len(ODL_VIDEO_FEATURES_PREFIX):]: get_any(key, None) for key
    in get_all_config_keys() if key.startswith(ODL_VIDEO_FEATURES_PREFIX)
}

MIDDLEWARE_FEATURE_FLAG_QS_PREFIX = get_string("MIDDLEWARE_FEATURE_FLAG_QS_PREFIX", None)
MIDDLEWARE_FEATURE_FLAG_COOKIE_NAME = get_string(
    'MIDDLEWARE_FEATURE_FLAG_COOKIE_NAME', 'ODL_VIDEO_FEATURE_FLAGS')
MIDDLEWARE_FEATURE_FLAG_COOKIE_MAX_AGE_SECONDS = get_int(
    'MIDDLEWARE_FEATURE_FLAG_COOKIE_MAX_AGE_SECONDS', 60 * 60)

if MIDDLEWARE_FEATURE_FLAG_QS_PREFIX:
    MIDDLEWARE_CLASSES = MIDDLEWARE_CLASSES + (
        'odl_video.middleware.QueryStringFeatureFlagMiddleware',
        'odl_video.middleware.CookieFeatureFlagMiddleware',
    )


# enable the nplusone profiler only in debug mode
if DEBUG:
    INSTALLED_APPS += (
        'nplusone.ext.django',
    )
    MIDDLEWARE_CLASSES += (
        'nplusone.ext.django.NPlusOneMiddleware',
    )


# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/

STATIC_URL = '/static/'

STATIC_ROOT = 'staticfiles'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

# OTHER
LOGIN_REDIRECT_URL = "/"

# Important to define this so DEBUG works properly
INTERNAL_IPS = (get_string('HOST_IP', '127.0.0.1'), )

# Configure e-mail settings
EMAIL_BACKEND = get_string('ODL_VIDEO_EMAIL_BACKEND', 'django.core.mail.backends.smtp.EmailBackend')
EMAIL_HOST = get_string('ODL_VIDEO_EMAIL_HOST', 'localhost')
EMAIL_PORT = get_int('ODL_VIDEO_EMAIL_PORT', 25)
EMAIL_HOST_USER = get_string('ODL_VIDEO_EMAIL_USER', '')
EMAIL_HOST_PASSWORD = get_string('ODL_VIDEO_EMAIL_PASSWORD', '')
EMAIL_USE_TLS = get_bool('ODL_VIDEO_EMAIL_TLS', False)
EMAIL_SUPPORT = get_string('ODL_VIDEO_SUPPORT_EMAIL', '<EMAIL>')
DEFAULT_FROM_EMAIL = get_string('ODL_VIDEO_FROM_EMAIL', 'webmaster@localhost')

MAILGUN_URL = get_string('MAILGUN_URL', None)
MAILGUN_KEY = get_string('MAILGUN_KEY', None)
MAILGUN_BATCH_CHUNK_SIZE = get_int('MAILGUN_BATCH_CHUNK_SIZE', 1000)
MAILGUN_RECIPIENT_OVERRIDE = get_string('MAILGUN_RECIPIENT_OVERRIDE', None)
MAILGUN_FROM_EMAIL = get_string('MAILGUN_FROM_EMAIL', '<EMAIL>')
MAILGUN_BCC_TO_EMAIL = get_string('MAILGUN_BCC_TO_EMAIL', '<EMAIL>')


# e-mail configurable admins
ADMIN_EMAIL = get_string('ODL_VIDEO_ADMIN_EMAIL', '')
if ADMIN_EMAIL != '':
    ADMINS = (('Admins', ADMIN_EMAIL),)
else:
    ADMINS = ()

# Logging configuration
LOG_LEVEL = get_string('ODL_VIDEO_LOG_LEVEL', 'INFO')
DJANGO_LOG_LEVEL = get_string('DJANGO_LOG_LEVEL', 'INFO')
SENTRY_LOG_LEVEL = get_string('SENTRY_LOG_LEVEL', 'ERROR')

# For logging to a remote syslog host
LOG_HOST = get_string('ODL_VIDEO_LOG_HOST', 'localhost')
LOG_HOST_PORT = get_int('ODL_VIDEO_LOG_HOST_PORT', 514)

HOSTNAME = platform.node().split('.')[0]

# nplusone profiler logger configuration
NPLUSONE_LOGGER = logging.getLogger('nplusone')
NPLUSONE_LOG_LEVEL = logging.ERROR

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse',
        }
    },
    'formatters': {
        'verbose': {
            'format': (
                '[%(asctime)s] %(levelname)s %(process)d [%(name)s] '
                '%(filename)s:%(lineno)d - '
                '[{hostname}] - %(message)s'
            ).format(hostname=HOSTNAME),
            'datefmt': '%Y-%m-%d %H:%M:%S'
        }
    },
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose'
        },
        'syslog': {
            'level': LOG_LEVEL,
            'class': 'logging.handlers.SysLogHandler',
            'facility': 'local7',
            'formatter': 'verbose',
            'address': (LOG_HOST, LOG_HOST_PORT)
        },
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        },
        'sentry': {
            'level': SENTRY_LOG_LEVEL,
            'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
            'formatter': 'verbose'
        },
    },
    'loggers': {
        'root': {
            'handlers': ['console', 'syslog'],
            'level': LOG_LEVEL,
        },
        'django': {
            'propagate': True,
            'level': DJANGO_LOG_LEVEL,
            'handlers': ['console', 'syslog'],
        },
        'django.request': {
            'handlers': ['mail_admins'],
            'level': DJANGO_LOG_LEVEL,
            'propagate': True,
        },
        'raven': {
            'level': SENTRY_LOG_LEVEL,
            'handlers': []
        },
        'nplusone': {
            'handlers': ['console'],
            'level': 'ERROR',
        }
    },
}

# Sentry
ENVIRONMENT = get_string('ODL_VIDEO_ENVIRONMENT', 'dev')
SENTRY_CLIENT = 'raven.contrib.django.raven_compat.DjangoClient'
RAVEN_CONFIG = {
    'dsn': get_string('SENTRY_DSN', ''),
    'environment': ENVIRONMENT,
    'release': VERSION
}<commit_msg>Fix config of root logger (#300)<commit_after>"""
Django settings for odl_video project.
"""
import logging
import os
import platform
from urllib.parse import urljoin

import dj_database_url
from django.core.exceptions import ImproperlyConfigured

from odl_video.envs import (
    get_any,
    get_bool,
    get_int,
    get_key,
    get_string,
)

VERSION = "0.2.1"

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

SECRET_KEY = get_string(
    'DJANGO_SECRET_KEY',
    'ls8t)o32h@bqp1s8e0&6+mepk#t4@^68yx43kjm_#tvdv=m&ke',
)

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = get_bool('DEBUG', False)

ALLOWED_HOSTS = ['*']


WEBPACK_LOADER = {
    'DEFAULT': {
        'CACHE': not DEBUG,
        'BUNDLE_DIR_NAME': 'bundles/',
        'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'),
        'POLL_INTERVAL': 0.1,
        'TIMEOUT': None,
        'IGNORE': [
            r'.+\.hot-update\.+',
            r'.+\.js\.map'
        ]
    }
}

# Request files from the webpack dev server
USE_WEBPACK_DEV_SERVER = get_bool('ODL_VIDEO_SERVICE_USE_WEBPACK_DEV_SERVER', False)
WEBPACK_DEV_SERVER_HOST = get_string('WEBPACK_DEV_SERVER_HOST', '')
WEBPACK_DEV_SERVER_PORT = get_int('WEBPACK_DEV_SERVER_PORT', 8082)


# Application definition

INSTALLED_APPS = [
    'ui.apps.UIConfig',
    'cloudsync.apps.CloudSyncConfig',
    'mail.apps.MailConfig',
    'dj_elastictranscoder',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'server_status',
    'raven.contrib.django.raven_compat',
]

SESSION_ENGINE = 'django.contrib.sessions.backends.signed_cookies'

DISABLE_WEBPACK_LOADER_STATS = get_bool("DISABLE_WEBPACK_LOADER_STATS", False)
if not DISABLE_WEBPACK_LOADER_STATS:
    INSTALLED_APPS += ('webpack_loader',)

MIDDLEWARE_CLASSES = [
    'raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

if get_bool('USE_SHIBBOLETH', False):
    # TOUCHSTONE
    MIDDLEWARE_CLASSES.append('shibboleth.middleware.ShibbolethRemoteUserMiddleware')
    SHIBBOLETH_ATTRIBUTE_MAP = {
        "EPPN": (True, "username"),
        "MAIL": (True, "email"),
        # full name is in the "DISPLAY_NAME" header,
        # but no way to parse that into first_name and last_name...
    }
    AUTHENTICATION_BACKENDS = [
        'shibboleth.backends.ShibbolethRemoteUserBackend',
    ]
    LOGIN_URL = "/Shibboleth.sso/Login"
else:
    LOGIN_URL = "/login/"

ROOT_URLCONF = 'odl_video.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'odl_video.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
# Uses DATABASE_URL to configure with sqlite default:
# For URL structure:
# https://github.com/kennethreitz/dj-database-url
DEFAULT_DATABASE_CONFIG = dj_database_url.parse(
    get_string(
        'DATABASE_URL',
        'sqlite:///{0}'.format(os.path.join(BASE_DIR, 'db.sqlite3'))
    )
)
DEFAULT_DATABASE_CONFIG['CONN_MAX_AGE'] = get_int('ODL_VIDEO_DB_CONN_MAX_AGE', 0)

if get_bool('ODL_VIDEO_DB_DISABLE_SSL', False):
    DEFAULT_DATABASE_CONFIG['OPTIONS'] = {}
else:
    DEFAULT_DATABASE_CONFIG['OPTIONS'] = {'sslmode': 'require'}

DATABASES = {
    'default': DEFAULT_DATABASE_CONFIG
}


# the full URL of the current application is mandatory
ODL_VIDEO_BASE_URL = get_string('ODL_VIDEO_BASE_URL', None)

# Celery
# http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html
REDIS_URL = get_string("REDIS_URL", None)
USE_CELERY = True
CELERY_RESULT_BACKEND = CELERY_BROKER_URL = REDIS_URL

CELERY_TASK_ALWAYS_EAGER = get_bool("CELERY_TASK_ALWAYS_EAGER", False)
CELERY_TASK_EAGER_PROPAGATES = get_bool("CELERY_TASK_EAGER_PROPAGATES", True)

CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TIMEZONE = 'UTC'
CELERY_BEAT_SCHEDULE = {
    'update-statuses': {
        'task': 'cloudsync.tasks.update_video_statuses',
        'schedule': get_int('VIDEO_STATUS_UPDATE_FREQUENCY', 60)
    },
    'watch-bucket': {
        'task': 'cloudsync.tasks.monitor_watch_bucket',
        'schedule': get_int('VIDEO_WATCH_BUCKET_FREQUENCY', 900)
    }
}

# django cache back-ends
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
        'LOCATION': 'local-in-memory-cache',
    },
    'redis': {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": CELERY_BROKER_URL,
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient"
        },
    },
}


# features flags
def get_all_config_keys():
    """Returns all the configuration keys from both environment and configuration files"""
    return list(os.environ.keys())


ODL_VIDEO_FEATURES_PREFIX = get_string('ODL_VIDEO_FEATURES_PREFIX', 'FEATURE_')
FEATURES = {
    key[len(ODL_VIDEO_FEATURES_PREFIX):]: get_any(key, None) for key
    in get_all_config_keys() if key.startswith(ODL_VIDEO_FEATURES_PREFIX)
}

MIDDLEWARE_FEATURE_FLAG_QS_PREFIX = get_string("MIDDLEWARE_FEATURE_FLAG_QS_PREFIX", None)
MIDDLEWARE_FEATURE_FLAG_COOKIE_NAME = get_string(
    'MIDDLEWARE_FEATURE_FLAG_COOKIE_NAME', 'ODL_VIDEO_FEATURE_FLAGS')
MIDDLEWARE_FEATURE_FLAG_COOKIE_MAX_AGE_SECONDS = get_int(
    'MIDDLEWARE_FEATURE_FLAG_COOKIE_MAX_AGE_SECONDS', 60 * 60)

if MIDDLEWARE_FEATURE_FLAG_QS_PREFIX:
    MIDDLEWARE_CLASSES = MIDDLEWARE_CLASSES + (
        'odl_video.middleware.QueryStringFeatureFlagMiddleware',
        'odl_video.middleware.CookieFeatureFlagMiddleware',
    )


# enable the nplusone profiler only in debug mode
if DEBUG:
    INSTALLED_APPS += (
        'nplusone.ext.django',
    )
    MIDDLEWARE_CLASSES += (
        'nplusone.ext.django.NPlusOneMiddleware',
    )


# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/

STATIC_URL = '/static/'

STATIC_ROOT = 'staticfiles'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

# OTHER
LOGIN_REDIRECT_URL = "/"

# Important to define this so DEBUG works properly
INTERNAL_IPS = (get_string('HOST_IP', '127.0.0.1'), )

# Configure e-mail settings
EMAIL_BACKEND = get_string('ODL_VIDEO_EMAIL_BACKEND', 'django.core.mail.backends.smtp.EmailBackend')
EMAIL_HOST = get_string('ODL_VIDEO_EMAIL_HOST', 'localhost')
EMAIL_PORT = get_int('ODL_VIDEO_EMAIL_PORT', 25)
EMAIL_HOST_USER = get_string('ODL_VIDEO_EMAIL_USER', '')
EMAIL_HOST_PASSWORD = get_string('ODL_VIDEO_EMAIL_PASSWORD', '')
EMAIL_USE_TLS = get_bool('ODL_VIDEO_EMAIL_TLS', False)
EMAIL_SUPPORT = get_string('ODL_VIDEO_SUPPORT_EMAIL', '<EMAIL>')
DEFAULT_FROM_EMAIL = get_string('ODL_VIDEO_FROM_EMAIL', 'webmaster@localhost')

MAILGUN_URL = get_string('MAILGUN_URL', None)
MAILGUN_KEY = get_string('MAILGUN_KEY', None)
MAILGUN_BATCH_CHUNK_SIZE = get_int('MAILGUN_BATCH_CHUNK_SIZE', 1000)
MAILGUN_RECIPIENT_OVERRIDE = get_string('MAILGUN_RECIPIENT_OVERRIDE', None)
MAILGUN_FROM_EMAIL = get_string('MAILGUN_FROM_EMAIL', '<EMAIL>')
MAILGUN_BCC_TO_EMAIL = get_string('MAILGUN_BCC_TO_EMAIL', '<EMAIL>')


# e-mail configurable admins
ADMIN_EMAIL = get_string('ODL_VIDEO_ADMIN_EMAIL', '')
if ADMIN_EMAIL != '':
    ADMINS = (('Admins', ADMIN_EMAIL),)
else:
    ADMINS = ()

# Logging configuration
LOG_LEVEL = get_string('ODL_VIDEO_LOG_LEVEL', 'INFO')
DJANGO_LOG_LEVEL = get_string('DJANGO_LOG_LEVEL', 'INFO')
SENTRY_LOG_LEVEL = get_string('SENTRY_LOG_LEVEL', 'ERROR')

# For logging to a remote syslog host
LOG_HOST = get_string('ODL_VIDEO_LOG_HOST', 'localhost')
LOG_HOST_PORT = get_int('ODL_VIDEO_LOG_HOST_PORT', 514)

HOSTNAME = platform.node().split('.')[0]

# nplusone profiler logger configuration
NPLUSONE_LOGGER = logging.getLogger('nplusone')
NPLUSONE_LOG_LEVEL = logging.ERROR

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse',
        }
    },
    'formatters': {
        'verbose': {
            'format': (
                '[%(asctime)s] %(levelname)s %(process)d [%(name)s] '
                '%(filename)s:%(lineno)d - '
                '[{hostname}] - %(message)s'
            ).format(hostname=HOSTNAME),
            'datefmt': '%Y-%m-%d %H:%M:%S'
        }
    },
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose'
        },
        'syslog': {
            'level': LOG_LEVEL,
            'class': 'logging.handlers.SysLogHandler',
            'facility': 'local7',
            'formatter': 'verbose',
            'address': (LOG_HOST, LOG_HOST_PORT)
        },
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        },
        'sentry': {
            'level': SENTRY_LOG_LEVEL,
            'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
            'formatter': 'verbose'
        },
    },
    'loggers': {
        'django': {
            'propagate': True,
            'level': DJANGO_LOG_LEVEL,
            'handlers': ['console', 'syslog'],
        },
        'django.request': {
            'handlers': ['mail_admins'],
            'level': DJANGO_LOG_LEVEL,
            'propagate': True,
        },
        'raven': {
            'level': SENTRY_LOG_LEVEL,
            'handlers': []
        },
        'nplusone': {
            'handlers': ['console'],
            'level': 'ERROR',
        }
    },
    'root': {
        'handlers': ['console', 'syslog'],
        'level': LOG_LEVEL,
    },
}

# Sentry
ENVIRONMENT = get_string('ODL_VIDEO_ENVIRONMENT', 'dev')
SENTRY_CLIENT = 'raven.contrib.django.raven_compat.DjangoClient'
RAVEN_CONFIG = {
    'dsn': get_string('SENTRY_DSN', ''),
    'environment': ENVIRONMENT,
    'release': VERSION
}
{'fraction_non_alphanumeric': 0.1325491873396065, 'fraction_numerical': 0.005688622754491018, 'mean_word_length': 3.5809169278996866, 'pattern_counts': {'":': 12, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2719508', 'n_tokens_mistral': 8482, 'n_tokens_neox': 8439, 'n_words': 1179}