如何给var / log文件夹写入权限来记录错误 [英] How to give write permission to var/log folder to log errors
本文介绍了如何给var / log文件夹写入权限来记录错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在django中使用python日志,我想将错误记录到var / log文件夹。我收到这个错误:
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'
以下是设置中的代码段.py
'handlers': {'exception_logs': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'formatter': 'simple',
'filename': '/var/log/exceptions.log',
},
},
推荐答案
首先,确保文件已创建
sudo touch /var/log/exceptions.log
然后将文件的所有权更改为服务器运行的用户。假设这是 www-data
:
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.
这篇关于如何给var / log文件夹写入权限来记录错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文