How to give write permission to var/log folder to

2019-08-15 06:17发布

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条回答
放荡不羁爱自由
2楼-- · 2019-08-15 06:38

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.

查看更多
登录 后发表回答