Skip to content

Commit

Permalink
Merge pull request #2768 from gitcoinco/logging-updates
Browse files Browse the repository at this point in the history
Adjust django logging to output to CW
  • Loading branch information
SaptakS authored Nov 12, 2018
2 parents 7da5896 + ab84bcb commit 68320db
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
47 changes: 36 additions & 11 deletions app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import environ
import raven
from boto3.session import Session
from easy_thumbnails.conf import Settings as easy_thumbnails_defaults

import warnings
Expand Down Expand Up @@ -218,18 +219,36 @@
if DEBUG and ENV == 'stage':
ELASTIC_APM['DEBUG'] = True

AWS_ACCESS_KEY_ID = env('AWS_ACCESS_KEY_ID', default='')
AWS_SECRET_ACCESS_KEY = env('AWS_SECRET_ACCESS_KEY', default='')
AWS_DEFAULT_REGION = env('AWS_DEFAULT_REGION', default='us-west-2')
AWS_LOG_GROUP = env('AWS_LOG_GROUP', default='Gitcoin')
AWS_LOG_LEVEL = env('AWS_LOG_LEVEL', default='DEBUG')
AWS_LOG_STREAM = env('AWS_LOG_STREAM', default=f'{ENV}-web')

if ENV not in ['local', 'test', 'staging', 'preview']:
boto3_session = Session(
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
region_name=AWS_DEFAULT_REGION
)
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'root': {
'level': 'WARNING',
'handlers': ['sentry'],
'handlers': ['sentry', 'console', 'watchtower'],
},
'formatters': {
'simple': {
'format': '%(asctime)s %(name)-12s [%(levelname)-8s] %(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S'
},
'cloudwatch': {
'format': '%(name)-12s [%(levelname)-8s] %(message)s',
},
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s '
'%(process)d %(thread)d %(message)s'
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
},
'handlers': {
Expand All @@ -241,22 +260,30 @@
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
}
},
'watchtower': {
'level': AWS_LOG_LEVEL,
'class': 'watchtower.django.DjangoCloudWatchLogHandler',
'boto3_session': boto3_session,
'log_group': AWS_LOG_GROUP,
'stream_name': AWS_LOG_STREAM,
'formatter': 'cloudwatch',
},
},
'loggers': {
'django.db.backends': {
'level': 'WARN',
'handlers': ['console'],
'level': 'WARNING',
'handlers': ['console', 'watchtower'],
'propagate': False,
},
'raven': {
'level': 'DEBUG',
'handlers': ['console'],
'handlers': ['console', 'watchtower'],
'propagate': False,
},
'sentry.errors': {
'level': 'DEBUG',
'handlers': ['console'],
'handlers': ['console', 'watchtower'],
'propagate': False,
},
},
Expand All @@ -275,6 +302,7 @@
LOGGING['root']['handlers'] = ['sentry', 'elasticapm']

LOGGING['loggers']['django.request'] = LOGGING['loggers']['django.db.backends']
LOGGING['loggers']['django.security.*'] = LOGGING['loggers']['django.db.backends']
for ia in INSTALLED_APPS:
LOGGING['loggers'][ia] = LOGGING['loggers']['django.db.backends']
else:
Expand Down Expand Up @@ -551,9 +579,6 @@
IGNORE_COMMENTS_FROM = ['gitcoinbot', ]

# optional: only needed if you run the activity-report management command
AWS_ACCESS_KEY_ID = env('AWS_ACCESS_KEY_ID', default='')
AWS_SECRET_ACCESS_KEY = env('AWS_SECRET_ACCESS_KEY', default='')

AWS_STORAGE_BUCKET_NAME = env('AWS_STORAGE_BUCKET_NAME', default='')
AWS_S3_CACHE_MAX_AGE = env.str('AWS_S3_CACHE_MAX_AGE', default='15552000')
AWS_QUERYSTRING_EXPIRE = env.int('AWS_QUERYSTRING_EXPIRE', default=3600)
Expand Down
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ pydoc-markdown==2.0.4
oauth2client==4.1.3
pyvips==2.1.3
redis-semaphore

watchtower==0.5.4

0 comments on commit 68320db

Please sign in to comment.