Reputation: 1352
I am deploying a web service built on Django/Python at AWS using Elastic Beanstalk. I am using Django's logging feature to log website use and related data. While that worked fine with local testing, I an unable to get this to work with Beanstalk.
My code to log in settings.py
is:
# Django Logging
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt' : "%d/%b/%Y %H:%M:%S"
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': 'spareguru.log',
'formatter': 'verbose'
},
},
'loggers': {
'django': {
'handlers':['file'],
'propagate': True,
'level':'DEBUG',
},
'customer': {
'handlers': ['file'],
'level': 'DEBUG',
},
}
}
The error I get while deploying to Beanstalk is:
ValueError: Unable to configure handler 'file': [Errno 13] Permission denied: '/opt/python/bundle/3/app/spareguru.log'
I also tried creating a file using .ebextensions
and making wsgi
the owner of that file but that didn't work either.
How can I fix this?
Upvotes: 6
Views: 2560
Reputation: 14315
A bit late for the OP, but this may be useful for others:
If you call e.g. django-admin.py migrate
, or other django code, in your .ebextensions
container_commands
, that will cause the log file to be created with user root
and group root
(unless the file already exists).
In that case, you may need to change the file permissions after all the django calls have been made (in .ebextensions
), or just remove the log file, as explained in detail here.
Upvotes: 0
Reputation: 51
You do not have sufficient rights on the server for create log file. Сonfigure SSH and using CHMOD to change permission for folder
Configure the environment of your Elastic Beanstalk Application (for SSH) - enter link description here
Upvotes: 1