简体   繁体   English

使用 Elastic Beanstalk (AWS) 进行 Django 日志记录

[英]Django Logging with Elastic Beanstalk (AWS)

I am deploying a web service built on Django/Python at AWS using Elastic Beanstalk.我正在使用 Elastic Beanstalk 在 AWS 上部署基于 Django/Python 构建的 Web 服务。 I am using Django's logging feature to log website use and related data.我正在使用 Django 的日志记录功能来记录网站使用情况和相关数据。 While that worked fine with local testing, I an unable to get this to work with Beanstalk.虽然这在本地测试中运行良好,但我无法让它与 Beanstalk 一起使用。

My code to log in settings.py is:我登录settings.py代码是:

# Django Logging

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
            'datefmt' : "%d/%b/%Y %H:%M:%S"
        },
        'simple': {
        'format': '%(levelname)s %(message)s'
        },
    },
    'handlers': {
        'file': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'filename': 'spareguru.log',
            'formatter': 'verbose'
        },
    },
    'loggers': {
        'django': {
            'handlers':['file'],
            'propagate': True,
            'level':'DEBUG',
         },
        'customer': {
            'handlers': ['file'],
            'level': 'DEBUG',
         },
    }
}

The error I get while deploying to Beanstalk is:部署到 Beanstalk 时遇到的错误是:

ValueError: Unable to configure handler 'file': [Errno 13] Permission denied: '/opt/python/bundle/3/app/spareguru.log'

I also tried creating a file using .ebextensions and making wsgi the owner of that file but that didn't work either.我还尝试使用.ebextensions创建文件并使wsgi成为该文件的所有者,但这也不起作用。

How can I fix this?我怎样才能解决这个问题?

You do not have sufficient rights on the server for create log file.您在服务器上没有足够的权限来创建日志文件。 Сonfigure SSH and using CHMOD to change permission for folder配置 SSH 并使用 CHMOD 更改文件夹的权限

Configure the environment of your Elastic Beanstalk Application (for SSH) - enter link description here配置您的 Elastic Beanstalk 应用程序的环境(用于 SSH) - 在此处输入链接描述

A bit late for the OP, but this may be useful for others: OP 有点晚了,但这对其他人可能有用:

If you call eg django-admin.py migrate , or other django code, in your .ebextensions container_commands , that will cause the log file to be created with user root and group root (unless the file already exists).如果您在.ebextensions container_commands调用例如django-admin.py migrate或其他 django 代码,这将导致使用用户root和组root创建日志文件(除非该文件已存在)。

In that case, you may need to change the file permissions after all the django calls have been made (in .ebextensions ), or just remove the log file, as explained in detail here .在这种情况下,您可能需要所有 django 调用完成更改文件权限(在.ebextensions ),或者只是删除日志文件,详细解释见此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM