diff --git a/chatbot_ner/config.py b/chatbot_ner/config.py index 45616806..0e1af788 100644 --- a/chatbot_ner/config.py +++ b/chatbot_ner/config.py @@ -1,34 +1,12 @@ from __future__ import absolute_import -import logging.handlers +import logging import os from elasticsearch import RequestsHttpConnection from requests_aws4auth import AWS4Auth -BASE_DIR = os.path.dirname(os.path.dirname(__file__)) -LOG_PATH = os.path.join(BASE_DIR, 'logs') - -# TODO: Set this up via Django LOGGING -LOG_LEVEL = os.environ.get('DJANGO_LOG_LEVEL', 'error').upper() - -# Common formatter -formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s %(module)s:%(lineno)d") - -# Handler for Docker stdout -handler_stdout = logging.StreamHandler() -handler_stdout.setLevel(LOG_LEVEL) -handler_stdout.setFormatter(formatter) - -# SETUP NER LOGGING -NER_LOG_FILENAME = os.path.join(LOG_PATH, 'ner_log.log') -handler = logging.handlers.WatchedFileHandler(NER_LOG_FILENAME) -handler.setFormatter(formatter) - -ner_logger = logging.getLogger('NERLogger') -ner_logger.setLevel(LOG_LEVEL) -ner_logger.addHandler(handler) -ner_logger.addHandler(handler_stdout) +ner_logger = logging.getLogger('chatbot_ner') ENGINE = os.environ.get('ENGINE') # ES settings (Mandatory to use Text type entities) diff --git a/chatbot_ner/settings.py b/chatbot_ner/settings.py index 37c0864e..f06e3101 100755 --- a/chatbot_ner/settings.py +++ b/chatbot_ner/settings.py @@ -121,6 +121,69 @@ }, ] +DJANGO_LOG_LEVEL = os.environ.get('DJANGO_LOG_LEVEL', 'warning').upper() +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'filters': { + 'require_debug_false': { + '()': 'django.utils.log.RequireDebugFalse' + } + }, + 'formatters': { + 'default': { + 'format': '%(asctime)s %(levelname)s %(message)s %(module)s:%(lineno)d' + }, + }, + 'handlers': { + 'stdout': { + 'level': DJANGO_LOG_LEVEL, + 'class': 'logging.StreamHandler', + 'stream': sys.stdout, + 'formatter': 'default' + }, + 'requests_file': { + 'level': 'WARNING', + 'class': 'logging.handlers.WatchedFileHandler', + 'filename': os.path.join(BASE_DIR, 'logs', 'requests.log'), + 'formatter': 'default' + }, + 'chatbot_ner_file': { + 'level': DJANGO_LOG_LEVEL, + 'class': 'logging.handlers.WatchedFileHandler', + 'filename': os.path.join(BASE_DIR, 'logs', 'ner_log.log'), + 'formatter': 'default' + } + }, + 'loggers': { + 'django.request': { + 'handlers': ['chatbot_ner_file'], # TODO: switch to `requests_file` later + 'level': DJANGO_LOG_LEVEL, + 'propagate': True, + }, + 'django': { + 'handlers': ['stdout'], + 'level': DJANGO_LOG_LEVEL, + 'propagate': True, + }, + 'chatbot_ner': { + 'handlers': ['chatbot_ner_file'], + 'level': DJANGO_LOG_LEVEL, + 'propagate': False + }, + 'sentry_sdk.errors': { + 'handlers': ['stdout'], + 'level': 'WARNING', + 'propagate': True + }, + 'elasticapm': { + 'handlers': ['stdout'], + 'level': 'WARNING', + 'propagate': False + } + } +} + # setup sentry setup_sentry()