Commit 44827dbc authored by Lukas Burgey's avatar Lukas Burgey

Configure logging in django config

parent 924dbc80
from logging import Formatter, FileHandler, StreamHandler, getLogger
import sys
LOGGER_NAME = 'django_backend.backend'
LOGGER_DIR = './logs/'
FORMATTER = Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ERROR_FH = FileHandler(LOGGER_DIR + 'error.log')
ERROR_FH.setLevel('ERROR')
ERROR_FH.setFormatter(FORMATTER)
INFO_FH = FileHandler(LOGGER_DIR + 'info.log')
INFO_FH.setLevel('INFO')
INFO_FH.setFormatter(FORMATTER)
DEBUG_FH = FileHandler(LOGGER_DIR + 'debug.log')
DEBUG_FH.setLevel('DEBUG')
DEBUG_FH.setFormatter(FORMATTER)
# for the console
CH = StreamHandler(sys.stdout)
CH.setLevel('INFO')
CH.setFormatter(FORMATTER)
def setup_logger():
logger = getLogger(LOGGER_NAME)
logger.setLevel('DEBUG')
# add all handlers
logger.addHandler(ERROR_FH)
logger.addHandler(INFO_FH)
logger.addHandler(CH)
logger.addHandler(DEBUG_FH)
logger.info('STARTED LOGGER {}'.format(LOGGER_NAME))
......@@ -33,8 +33,8 @@ with open('.secret.key') as f:
DEBUG = True
ALLOWED_HOSTS = [
'hdf-portal.data.kit.edu'
]
'hdf-portal.data.kit.edu',
]
# Application definition
......@@ -151,3 +151,52 @@ REST_FRAMEWORK = {
'rest_framework.permissions.IsAuthenticated',
],
}
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'standard': {
'format': '%(asctime)s - %(name)s - %(levelname)s - %(message)s',
},
},
'handlers': {
'django': {
'class': 'logging.FileHandler',
'filename': './logs/django.log',
'formatter': 'standard',
},
'debug': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': './logs/debug.log',
'formatter': 'standard',
},
'info': {
'level': 'INFO',
'class': 'logging.FileHandler',
'filename': './logs/info.log',
'formatter': 'standard',
},
'error': {
'level': 'ERROR',
'class': 'logging.FileHandler',
'filename': './logs/error.log',
'formatter': 'standard',
},
'console': {
'class': 'logging.StreamHandler',
'formatter': 'standard',
},
},
'loggers': {
'django_backend': {
'handlers': ['debug', 'info', 'error'],
'level': 'DEBUG',
},
'django': {
'handlers': ['debug', 'info', 'error'],
'level': 'INFO',
},
},
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment