diff --git a/dal/settings.py b/dal/settings.py index 1cc50c3..db939af 100644 --- a/dal/settings.py +++ b/dal/settings.py @@ -11,28 +11,25 @@ https://docs.djangoproject.com/en/1.10/ref/settings/ """ import os -import dotenv +from decouple import config, Csv import ldap from django_auth_ldap.config import LDAPSearch, LDAPSearchUnion -# get config -dotenv.read_dotenv() - # LDAP setup -AUTH_LDAP_SERVER_URI = os.environ['LDAPSERVER'] -AUTH_LDAP_BIND_DN = os.environ['LDAPSEARCHUSER'] -AUTH_LDAP_BIND_PASSWORD = os.environ['LDAPSEARCHUSERPASSWORD'] +AUTH_LDAP_SERVER_URI = config('LDAPSERVER') +AUTH_LDAP_BIND_DN = config('LDAPSEARCHUSER') +AUTH_LDAP_BIND_PASSWORD = config('LDAPSEARCHUSERPASSWORD') # Search union over OUs -search_base = os.environ['LDAPSEARCH'].split() +search_base = config('LDAPSEARCH').split() search_base_ldap = [ LDAPSearch(x, ldap.SCOPE_SUBTREE, "(uid=%(user)s)") for x in search_base ] AUTH_LDAP_USER_SEARCH = LDAPSearchUnion(*search_base_ldap) -AUTH_LDAP_START_TLS = os.environ.get('LDAP_USE_TLS', False) +AUTH_LDAP_START_TLS = config('LDAP_USE_TLS', default=False, cast=bool) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -DEBUG = os.environ.get('DEBUG', False) +DEBUG = config('DEBUG', default=False, cast=bool) ALLOWED_HOSTS = (os.environ.get('ALLOWED_HOSTS', 'localhost')).split(",") @@ -133,4 +130,43 @@ DATABASES = { 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } -SECRET_KEY = os.environ.get('SECRET_KEY') +SECRET_KEY = config('SECRET_KEY') + + +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 os.environ.get('ENABLE_DEBUG_LOG', '').strip().lower() == "true": + loggers_dict = {} + modules_to_log_list = os.environ.get('MODULES_TO_LOG', 'django').split(',') + for custom_module in modules_to_log_list: + logger_item = { + custom_module: { + 'handlers': ['default'], + 'level': 'INFO', + 'propagate': True + } + } + loggers_dict.update(logger_item) + + LOGGING['loggers'] = loggers_dict diff --git a/requirements.txt b/requirements.txt index f6d34b1..3f3ab68 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ django django-auth-ldap python-ldap -django-dotenv django-bootstrap3 -django-filter==2.1.0 \ No newline at end of file +django-filter==2.1.0 +python-decouple