Python on the AWS Beanstalk. How to snapshot custom logs?
Asked Answered
D

2

16

I'm developing python application which works on aws beanstalk environment. For error handling and debugging proposes I write logs to custom lof file on the directory /var/logs/.

What should I do in order to have ability snapshot logs from Elastic beanstalk management console?

Dree answered 23/2, 2013 at 7:12 Comment(0)
D
7

If you need have ability to snapshot log files from Beanstalk management console, you should just write you log files to "/opt/python/log/" folder. Elastic beanstalk scripts use this folder for log tailing.

Dree answered 3/3, 2013 at 7:7 Comment(3)
I get Permission denied when I try that.Bathometer
Chuck what exactly did you try?Dree
logging.basicConfig(filename='/opt/python/log/my_log.log',level=logging.DEBUG)Bathometer
B
24

Expanding on Vadim911 (and my own comment), I solved the problem using a config file in .ebextensions. Here is the python code:

import logging
logging.basicConfig(filename='/opt/python/log/my.log', level=logging.DEBUG)

Here is the .ebextensions config file code:

files:
  "/opt/python/log/my.log" :
   mode: "000666"
   owner: ec2-user
   group: ec2-user
   content: |
       # Askbot log file

The contents of this file (along with other log files) is available using the Logs snapshot function on the AWS elastic beanstalk console.

Bathometer answered 21/5, 2014 at 17:25 Comment(1)
True, but there is no need to create the file in .ebextensions, as logging will do that for you when the file-handler is first initialized. If you run into a PermissionError, try removing the log file at the end of container_commands as explained here.Maintenance
D
7

If you need have ability to snapshot log files from Beanstalk management console, you should just write you log files to "/opt/python/log/" folder. Elastic beanstalk scripts use this folder for log tailing.

Dree answered 3/3, 2013 at 7:7 Comment(3)
I get Permission denied when I try that.Bathometer
Chuck what exactly did you try?Dree
logging.basicConfig(filename='/opt/python/log/my_log.log',level=logging.DEBUG)Bathometer

© 2022 - 2024 — McMap. All rights reserved.