【问题标题】:How to give write permission to var/log folder to log errors如何为 var/log 文件夹授予写入权限以记录错误
【发布时间】:2015-12-21 21:21:15
【问题描述】:

我在 django 中使用 python 日志记录,我想将错误记录到 var/log 文件夹。我收到此错误:

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

下面是我在settings.py中的代码sn-p

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

【问题讨论】:

    标签: django python-3.x logging error-logging


    【解决方案1】:

    首先,确保文件已经创建

    sudo touch /var/log/exceptions.log
    

    然后将文件的所有权更改为服务器运行的用户。假设这是www-data

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

    或者,您可以更改文件的组所有者,并将用户添加到该组。

    【讨论】:

    • 例如,我已经用 wordpress 试过了,这样做没关系。未写入 /var/log/httpd/ 文件夹中的自定义 PHP 应用程序日志文件。
    猜你喜欢
    • 2013-01-17
    • 2018-03-25
    • 2019-06-18
    • 1970-01-01
    • 2014-11-29
    • 1970-01-01
    • 2011-09-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多