Reputation: 1008
I am using Digitalocean one click Django server deployment using below version of Python, Django and Gunicorn.
gunicorn (version 19.7.1)
python 2.7
I can't seem to figure out how to log my access logs into a file. Below is my gunicorn.service file.
[Unit]
Description=Gunicorn daemon for Django Project
Before=nginx.service
After=network.target
[Service]
WorkingDirectory=/home/django/egre
ExecStart=/usr/bin/gunicorn --name=egre --pythonpath=/home/django/egre --bind unix:/home/django/gunicorn.socket --config /etc/gunicorn.d/gunicorn.py --access-logfile /var/log/emperor.log eGRE.wsgi:application
Restart=always
SyslogIdentifier=gunicorn
User=django
Group=django
[Install]
WantedBy=multi-user.target
https://docs.gunicorn.org/en/19.7.1/settings.html#logging
After following the above documentation I tried using --access-logfile=-
which works but does not log my stndout to a file after passing a relative path the gunicorn does not restart giving an exit-code 1.
How to write logs to emperor.log?
Upvotes: 1
Views: 2633
Reputation: 51938
I think you can try like this using django's logging:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': '/path/to/logger/gunicorn_access.log',
},
},
'loggers': {
'gunicorn.access': {
'handlers': ['file'],
'level': 'DEBUG',
'propagate': True,
},
},
}
Upvotes: 2