How to give write permission to var/log folder to log errors

二次信任 提交于 2019-12-24 17:17:33

问题


I am using python logging in django and I want to log errors to var/log folder. I am getting this error :

Unable to configure handler 'exception_logs': [Errno 2] No such file or directory: '/var/log/exceptions.log'

Below is my code snippet in settings.py

'handlers': {'exception_logs': {
        'level': 'DEBUG',
        'class': 'logging.FileHandler',
        'formatter': 'simple',
        'filename': '/var/log/exceptions.log',
    },
},

回答1:


First, make sure the file has been created

sudo touch /var/log/exceptions.log

Then change the ownership of the file to the user that the server runs as. Assuming this is www-data:

sudo chown www-data /var/log/exceptions.log

Alternatively, you could change the group owner of the file, and add the user to that group.



来源:https://stackoverflow.com/questions/32758523/how-to-give-write-permission-to-var-log-folder-to-log-errors

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