Enable logging by setting by setting ENABLE_DEBUG_LOG in .env

Also set the modules to log by using `MODULES_TO_LOG` config
parameter in .env
This commit is contained in:
PCoder 2019-02-03 10:13:13 +01:00
parent bbb6f3290d
commit 38c7283cb6

View file

@ -206,3 +206,34 @@ LOGGING = {
},
},
}
if config('ENABLE_DEBUG_LOG', False):
loggers_dict = {}
LOGGING['handlers']['file'] = {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': os.path.join(BASE_DIR, 'debug.log'),
}
MODULES_TO_LOG = config('MODULES_TO_LOG', 'django')
LOGGING['handlers']['file'] = {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': os.path.join(BASE_DIR, 'debug.log'),
}
if MODULES_TO_LOG is None:
# set MODULES_TO_LOG to django, if it is not set
MODULES_TO_LOG = 'django'
modules_to_log_list = MODULES_TO_LOG.split(',')
for custom_module in modules_to_log_list:
logger_item = {
custom_module: {
'handlers': ['file'],
'level': 'DEBUG',
'propagate': True
}
}
loggers_dict.update(logger_item)
LOGGING['loggers'] = loggers_dict