AWS Elastic Beanstalk logging with python (django)

前端 未结 7 1919
南笙
南笙 2020-12-05 02:52

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

I\'m using the following Logging configuration in my d

相关标签:
7条回答
  • 2020-12-05 03:44

    I had a similar issue but on Elastic Beanstalk, so I created a config file (e.g. applogs.config) in .ebextensions folder of the app. This creates the app-logs folder if it is not there already and sets the file permissions and owner so that the app can write its logs there.

    commands:
      00_create_dir:
        command: mkdir -p /var/log/app-logs
      01_change_permissions:
        command: chmod g+s /var/log/app-logs
      02_change_owner:
        command: chown wsgi:wsgi /var/log/app-logs
    

    Finally, in your Django settings:

    LOGGING = {
        'version': 1,
        'disable_existing_loggers': False,
        'handlers': {
            'file': {
                'level': 'DEBUG',
                'class': 'logging.FileHandler',
                'filename': '/var/log/app-logs/django.log',
            },
        },
        'loggers': {
            'django': {
                'handlers': ['file'],
                'level': 'DEBUG',
                'propagate': True,
            },
        },
    }
    

    Aditionally, if you want your log to be accessible from beanstalk logs using the web, add this to your file in .ebextensions

    files:
      "/opt/elasticbeanstalk/tasks/taillogs.d/django.conf":
        mode: "000755"
        owner: root
        group: root
        content: |
          /var/log/app-logs/django.log
    
    0 讨论(0)
提交回复
热议问题