Pratik Gujarathi
Pratik Gujarathi

Reputation: 965

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

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',
    },
},

Upvotes: 1

Views: 7494

Answers (1)

Alasdair
Alasdair

Reputation: 308949

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.

Upvotes: 7

Related Questions