-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
50 lines (45 loc) · 1.88 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from os.path import join, dirname
from dotenv import load_dotenv
import logging.handlers
import sys
import os
import nltk
"""
ENVIRONMENT
.env settings for local environments
"""
if os.path.isfile(os.path.join(os.path.dirname(__file__), '.env')):
dotenv_path = join(dirname(__file__), '.env')
load_dotenv(dotenv_path)
"""
nltk_data path spec
"""
nltk.data.path.append(os.environ.get('NLTK_DATA_PATH'))
"""
LOGGING
"""
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
stdoutHandler = logging.StreamHandler(sys.stdout)
stderrHandler = logging.StreamHandler(sys.stderr)
stderrHandler.setFormatter(formatter)
stdoutHandler.setFormatter(formatter)
paperTrailsHandler = logging.handlers.SysLogHandler(address=(os.environ.get('PAPERTRAILS_ADDRESS')
, int(os.environ.get('PAPERTRAILS_PORT'))))
paperTrailsHandler.setFormatter(formatter)
application_logger = logging.getLogger('BOLT')
if os.environ.get('ENVIRONMENT') == 'dev':
""" Only used for development purposes since werkzeug server is replaced by Apache and mod_wsgi in production """
werkzeug_logger = logging.getLogger('werkzeug')
werkzeug_logger.addHandler(stdoutHandler)
werkzeug_logger.addHandler(paperTrailsHandler)
werkzeug_logger.setLevel(logging.INFO)
application_logger.setLevel(logging.DEBUG)
application_logger.info("Running in development mode. Logging with level DEBUG")
elif os.environ.get('ENVIRONMENT') == 'test':
application_logger.addHandler(stdoutHandler)
application_logger.addHandler(paperTrailsHandler)
application_logger.setLevel(logging.INFO)
application_logger.info("Running in test mode. Logging with level INFO")
elif os.environ.get('ENVIRONMENT') == 'prod':
application_logger.setLevel(logging.INFO)
application_logger.info("Running in production mode. Logging with level INFO")