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

时间:2022-08-25 08:40:43

I am deploying a web service built on Django/Python at AWS using Elastic Beanstalk. I am using Django's logging feature to log website use and related data. While that worked fine with local testing, I an unable to get this to work with Beanstalk.

我正在使用Elastic Beanstalk在AWS上部署基于Django / Python构建的Web服务。我正在使用Django的日志记录功能来记录网站使用和相关数据。虽然这在本地测试中运行良好,但我无法使用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?

我怎样才能解决这个问题?

1 个解决方案

#1


1  

You do not have sufficient rights on the server for create log file. Сonfigure SSH and using CHMOD to change permission for folder

您在创建日志文件的服务器上没有足够的权限。 СonfigureSSH并使用CHMOD更改文件夹的权限

Configure the environment of your Elastic Beanstalk Application (for SSH) - enter link description here

配置Elastic Beanstalk应用程序的环境(用于SSH)​​ - 在此处输入链接描述

#1


1  

You do not have sufficient rights on the server for create log file. Сonfigure SSH and using CHMOD to change permission for folder

您在创建日志文件的服务器上没有足够的权限。 СonfigureSSH并使用CHMOD更改文件夹的权限

Configure the environment of your Elastic Beanstalk Application (for SSH) - enter link description here

配置Elastic Beanstalk应用程序的环境(用于SSH)​​ - 在此处输入链接描述