Load configs from .env and add basic logging config
This commit is contained in:
parent
e45e5989db
commit
fd0f0b56bd
1 changed files with 43 additions and 2 deletions
|
@ -10,6 +10,8 @@ For the full list of settings and their values, see
|
||||||
https://docs.djangoproject.com/en/2.1/ref/settings/
|
https://docs.djangoproject.com/en/2.1/ref/settings/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from decouple import config, Csv
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||||
|
@ -20,7 +22,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
SECRET_KEY = 'h^*!&u7yaac_6t02kk4de%$aagp6_j#+_wnw3@rqu6os0tlv#r'
|
SECRET_KEY = config('SECRET_KEY')
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
|
|
||||||
|
@ -129,7 +131,7 @@ DEBUG_DATABASES = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG = False
|
DEBUG = config('DEBUG', False, cast=bool)
|
||||||
ALLOWED_HOSTS = [
|
ALLOWED_HOSTS = [
|
||||||
".ungleich.ch"
|
".ungleich.ch"
|
||||||
]
|
]
|
||||||
|
@ -146,6 +148,45 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
STATIC_ROOT = os.path.join(BASE_DIR, "static")
|
STATIC_ROOT = os.path.join(BASE_DIR, "static")
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = '/static/'
|
||||||
|
|
||||||
|
LOGGING = {
|
||||||
|
'disable_existing_loggers': False,
|
||||||
|
'version': 1,
|
||||||
|
'formatters': {
|
||||||
|
'standard': {
|
||||||
|
'format': '%(asctime)s %(levelname)s %(name)s: %(message)s'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'handlers': {
|
||||||
|
'default': {
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'class': 'logging.handlers.RotatingFileHandler',
|
||||||
|
'filename': 'logs/debug.log',
|
||||||
|
'maxBytes': 1024*1024*5,
|
||||||
|
'backupCount': 10,
|
||||||
|
'formatter': 'standard',
|
||||||
|
},
|
||||||
|
'console': {
|
||||||
|
'class': 'logging.StreamHandler',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if config('ENABLE_DEBUG_LOG', cast=bool, default=False):
|
||||||
|
loggers_dict = {}
|
||||||
|
modules_to_log_list = config(
|
||||||
|
'MODULES_TO_LOG', default='django', cast=Csv()
|
||||||
|
)
|
||||||
|
for custom_module in modules_to_log_list:
|
||||||
|
logger_item = {
|
||||||
|
custom_module: {
|
||||||
|
'handlers': ['default'],
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'propagate': True
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loggers_dict.update(logger_item)
|
||||||
|
|
||||||
|
LOGGING['loggers'] = loggers_dict
|
||||||
|
|
||||||
|
|
||||||
if "DEBUG" in os.environ:
|
if "DEBUG" in os.environ:
|
||||||
|
|
Loading…
Reference in a new issue