Django: Setup an efficient logging system for a website in production

风流意气都作罢 提交于 2019-12-24 02:34:07

问题


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.

  1. Is it standard practice to keep Django logs in /var/log/?
  2. What type of permissions I need for the logs to store in /var/log.
  3. 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:


  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,
            },
        },
    }
    
  2. Refer this for setting up suitable permissions for log files: Permission Denied when writing log file

  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!