使用Python(django)的AWS Elastic Beanstalk日志记录 [英] AWS Elastic Beanstalk logging with python (django)

查看:75
本文介绍了使用Python(django)的AWS Elastic Beanstalk日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何在AWS Elastic beantalk中管理应用程序日志?您将应用程序写入哪个文件登录?

How do you manage your application logs in AWS elastic beanstalk? Which file you write you application logs to?

我在开发环境中使用以下日志记录配置,但是当我在AWS中进行部署时,此配置不起作用.

I'm using the following Logging configuration in my development environment but this doesn't work when I deploy in AWS.

DEBUG_LOG_DIR = BASE_DIR + "/django_debug.log"
LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    # How to format the output
    'formatters': {
        'standard': {
            'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
            'datefmt' : "%d/%b/%Y %H:%M:%S"
        },
    },
    # Log handlers (where to go)
    'handlers': {
        'null': {
            'level':'DEBUG',
            'class':'django.utils.log.NullHandler',
        },
        'log_file': {
            'level':'DEBUG',
            'class':'logging.handlers.RotatingFileHandler',
            'filename': DEBUG_LOG_DIR,
            'maxBytes': 50000,
            'backupCount': 2,
            'formatter': 'standard',
        },
        'console':{
            'level':'INFO',
            'class':'logging.StreamHandler',
            'formatter': 'standard'
        },
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler',
        },
    },
    # Loggers (where does the log come from)
    'loggers': {
        'repackager': {
            'handlers': ['console', 'log_file'],
            'level': 'DEBUG',
            'propagate': True,
        },
        'django': {
            'handlers':['console'],
            'propagate': True,
            'level':'WARN',
        },
        'django.db.backends': {
            'handlers': ['console', 'log_file'],
            'level': 'WARN',
            'propagate': False,
        },
        '': {
            'handlers': ['console', 'log_file'],
            'level': 'DEBUG',
        },
    }
}

推荐答案

好,我想出了一种方法.

Ok, I figured out a way to do it.

首先,我通过ssh连接到ec2机器,然后在/var/log中以root用户创建一个名为app_logs的文件夹:

First I connected via ssh to ec2 machine, then I create a folder in /var/log called app_logs with root user:

mkdir /var/log/app_logs

此后,我执行了以下操作:

After that I did the follow:

cd /var/log/
chmod g+s app_logs/
setfacl -d -m g::rw app_logs/
chown wsgi:wsgi app_logs/

这可确保在此文件夹中创建的所有文件都将wsgi作为所有者,并且对于该文件所属的组是可写的. 之所以必须这样做,是因为我注意到django应用程序创建的日志文件具有root作为所有者和所有者组,但是该应用程序通过wsgi用户运行.

That ensures that all the files created in this folder will have wsgi as owner and will be writable for the group that the file belongs. I had to do that because I noticed that the log file created by django app had root as owner and owner group but the application runs through wsgi user.

最后,我将DEBUG_LOG_DIR更改为/var/log/app_logs/django_debug.log

Finally I changed DEBUG_LOG_DIR to /var/log/app_logs/django_debug.log

这篇关于使用Python(django)的AWS Elastic Beanstalk日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆