问题
Alright so the development phase is over and now my website is live in prod. However, I have not set up the logging. My website is located in /var/www/html dir. Ideally I would like to have Django logging in /var/log/django but that would require permissions.
- Is it standard practice to keep Django logs in /var/log/?
- What type of permissions I need for the logs to store in /var/log.
- I just want logs for last 2 days and today, rest can automatically be removed if I can.
Setup: RHEL7, Apache2.4, python3.5, Django 1.10, mod_wsgi, mySQL
回答1:
No its not standard. Add the following statements to settings.py and modify the log file path to your needs:
LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'handlers': { 'file': { 'level': 'DEBUG', 'class': 'logging.FileHandler', 'filename': '/path/to/django/debug.log', }, }, 'loggers': { 'django': { 'handlers': ['file'], 'level': 'DEBUG', 'propagate': True, }, }, }
Refer this for setting up suitable permissions for log files: Permission Denied when writing log file
You will have to use logrotate otherwise make use of kafka server to maintain logs.
来源:https://stackoverflow.com/questions/42928869/django-setup-an-efficient-logging-system-for-a-website-in-production