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

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

问题描述

您如何在 AWS elastic beanstalk 中管理您的应用程序日志?您将应用程序日志写入哪个文件?

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

之后我做了以下事情:

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天全站免登陆