From 96bf851ea9554631885399ededae9ce44e65a9f9 Mon Sep 17 00:00:00 2001 From: Chirag Jain Date: Wed, 20 Oct 2021 16:01:50 +0530 Subject: [PATCH 1/3] Bump newrelic to `5.24.0.153` for compatibility with Django 3.2 Closes #446 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1f3b8017..24666cca 100644 --- a/requirements.txt +++ b/requirements.txt @@ -38,7 +38,7 @@ https://github.com/explosion/spacy-models/releases/download/de_core_news_sm-2.3. https://github.com/explosion/spacy-models/releases/download/es_core_news_sm-2.3.1/es_core_news_sm-2.3.1.tar.gz#egg=es_core_news_sm # Alerting and APMs -newrelic==3.4.0.95 +newrelic==5.24.0.153 elastic-apm==6.5.0 sentry-sdk==1.3.0 From ed80f5ac21a068e2b6ead081cffdd71f28685247 Mon Sep 17 00:00:00 2001 From: Chirag Jain Date: Wed, 10 Nov 2021 15:36:52 +0530 Subject: [PATCH 2/3] fix(logging): set up loggers using django's `settings.LOGGING` to be able to log request tracebacks --- chatbot_ner/config.py | 26 ++--------------- chatbot_ner/settings.py | 63 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 24 deletions(-) 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..e4b42abe 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() From 390d911e7bdc2a1353a988d2965b5864de699ed0 Mon Sep 17 00:00:00 2001 From: Chirag Jain Date: Wed, 10 Nov 2021 17:20:33 +0530 Subject: [PATCH 3/3] Remove an extra `"` from the formatter --- chatbot_ner/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chatbot_ner/settings.py b/chatbot_ner/settings.py index e4b42abe..f06e3101 100755 --- a/chatbot_ner/settings.py +++ b/chatbot_ner/settings.py @@ -132,7 +132,7 @@ }, 'formatters': { 'default': { - 'format': '"%(asctime)s %(levelname)s %(message)s %(module)s:%(lineno)d' + 'format': '%(asctime)s %(levelname)s %(message)s %(module)s:%(lineno)d' }, }, 'handlers': {