user1126167 user1126167 - 1 year ago 269
Python Question

AWS Elastic Beanstalk logging with python (django)

How do you manage your application logs in AWS elastic beanstalk? I mean you write you application logs to which file?
I'm using the following Logging configuration in my development environment but this doesn't work when I deploy in AWS.

Thanks in advance!

DEBUG_LOG_DIR = BASE_DIR + "/django_debug.log"
'version': 1,
'disable_existing_loggers': True,
# How to format the output
'formatters': {
'standard': {
'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt' : "%d/%b/%Y %H:%M:%S"
# Log handlers (where to go)
'handlers': {
'null': {
'log_file': {
'filename': DEBUG_LOG_DIR,
'maxBytes': 50000,
'backupCount': 2,
'formatter': 'standard',
'formatter': 'standard'
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler',
# Loggers (where does the log come from)
'loggers': {
'repackager': {
'handlers': ['console', 'log_file'],
'level': 'DEBUG',
'propagate': True,
'django': {
'propagate': True,
'django.db.backends': {
'handlers': ['console', 'log_file'],
'level': 'WARN',
'propagate': False,
'': {
'handlers': ['console', 'log_file'],
'level': 'DEBUG',

Answer Source

Ok, I figured out a way to do it.

First I connected via ssh to ec2 machine, then I create a folder in /var/log called app_logs with root user:

mkdir /var/log/app_logs

After that I did the follow:

cd /var/log/
chmod g+s app_logs/
setfacl -d -m g::rw app_logs/
chown wsgi:wsgi app_logs/

That ensures that all the files created in this folder will have wsgi as owner and will be writable for the group that the file belongs. I had to do that because I noticed that the log file created by django app had root as owner and owner group but the application runs through wsgi user.

Finally I changed DEBUG_LOG_DIR to /var/log/app_logs/django_debug.log

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download