Skip to content

Commit

Permalink
Merge pull request #449 from hellohaptik/develop
Browse files Browse the repository at this point in the history
Develop to Master 2021-11-10T19:47:00
  • Loading branch information
chiragjn authored Nov 15, 2021
2 parents f6187ab + 7421047 commit 5845f01
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 25 deletions.
26 changes: 2 additions & 24 deletions chatbot_ner/config.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
63 changes: 63 additions & 0 deletions chatbot_ner/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5845f01

Please sign in to comment.