Last active
October 12, 2021 20:33
-
-
Save andrewp-as-is/d39b0793da1e0314b37bff616fa64383 to your computer and use it in GitHub Desktop.
Django settings AWS logging CloudWatch #django #aws
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# DJANGO PRODUCTION SETTINGS | |
import logging | |
from boto3.session import Session | |
import os | |
from ._base_django import * | |
AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID') | |
AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY') | |
AWS_REGION_NAME = os.getenv('AWS_REGION_NAME') | |
boto3_session = Session(aws_access_key_id=AWS_ACCESS_KEY_ID, | |
aws_secret_access_key=AWS_SECRET_ACCESS_KEY, | |
region_name=AWS_REGION_NAME) | |
""" | |
'root': { | |
'level': logging.ERROR, | |
'handlers': ['console'], | |
}, | |
""" | |
LOGGING = { | |
'version': 1, | |
'disable_existing_loggers': False, | |
'formatters': { | |
'simple': { | |
'format': u"%(asctime)s [%(levelname)-8s] %(message)s", | |
'datefmt': "%Y-%m-%d %H:%M:%S" | |
}, | |
'aws': { | |
# you can add specific format for aws here | |
'format': u"%(asctime)s [%(levelname)-8s] %(message)s", | |
'datefmt': "%Y-%m-%d %H:%M:%S" | |
}, | |
}, | |
'handlers': { | |
'watchtower': { | |
'level': 'DEBUG', | |
'class': 'watchtower.CloudWatchLogHandler', | |
'boto3_session': boto3_session, | |
'log_group': 'MyLogGroupName', | |
'stream_name': 'MyStreamName', | |
'formatter': 'aws', | |
}, | |
}, | |
'loggers': { | |
'django': { | |
'level': 'INFO', | |
'handlers': ['watchtower'], | |
'propagate': False, | |
}, | |
# add your other loggers here... | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment