Reputation: 7136
I am using Django watchtower to log events to AWS Cloudwatch and added logging configs in the settings file.
development.py
boto3_session = Session(
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
region_name=AWS_REGION)
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'simple': {
'format': "%(asctime)s [%(levelname)-8s] %(message)s",
'datefmt': "%Y-%m-%d %H:%M:%S"
},
'aws': {
# you can add specific format for aws here
'format': "%(asctime)s [%(levelname)-8s] %(message)s",
'datefmt': "%Y-%m-%d %H:%M:%S"
},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
'watchtower': {
'level': 'INFO',
'class': 'watchtower.CloudWatchLogHandler',
'boto3_session': boto3_session,
'log_group': 'StagingBeagleApi',
'stream_name': 'ApplicationLogStream',
'formatter': 'aws',
},
},
'loggers': {
'django': {
'level': 'INFO',
'handlers': ['watchtower'],
'propagate': True,
},
},
}
However when I run my server, I don't get any error in the console but my site is not accessible anymore via locahost:3000, I get an ERR_CONNECTION_REFUSED
Please help!
UPDATE
If I replace the django
key with watchtower
it works. However, I want to put all Django logs into Cloudwatch and I followed the documentation which has the logger key as django
.
Upvotes: 7
Views: 940
Reputation: 163
You can pass another value beside the array ['watchtower'], which may resolve the issue. You can check the below code as a sample.
'loggers': { 'django': { 'level': 'INFO', 'handlers': ['watchtower','django'], 'propagate': True, }, },
Upvotes: 0