I want to customize my log files in AWS Elastic Beanstalk, and be sure that my custom application logs are included and streamed to Amazon CloudWatch.
Short Description
If the default log files that Elastic Beanstalk collects and streams don't meet the needs of your application or use case, then consider the following options to customize the collection and streaming of your log files:
- Include your custom logs in the log bundle
- Rotate your logs
- (Optional) Stream your logs to CloudWatch
Note: If you have a custom log file or if one of your logs is missing from the default logs, then you can further customize your log configuration.
Resolution
Include your custom logs in the log bundle
When you request logs from Elastic Beanstalk, Elastic Beanstalk returns default log files from the Amazon Elastic Compute Cloud (Amazon EC2) instances in your environment. However, you might not receive these default log files if your application has a unique log location.
To get Elastic Beanstalk to return your log files from a unique log location, extend the default log task configuration.
Rotate your logs
To prevent your application log files from taking up too much disk space or even exhausting disk space, rotate your old log files with log rotation.
Rotating your logs makes sure that old logs are deleted automatically from your environment's EC2 instances. If you want your old logs to persist, you can enable rotated logs to be uploaded to Amazon Simple Storage Service (Amazon S3) before the logs are deleted from an instance.
(Optional) Stream your logs to CloudWatch
In production applications, it's a best practice to stream your logs to a remote storage solution, such as CloudWatch. To learn how to enable log streaming on Elastic Beanstalk, see Streaming Log Files to Amazon CloudWatch Logs or Using Elastic Beanstalk with Amazon CloudWatch Logs.
If you want to stream custom log locations, see Instance Log Streaming Using Configuration Files.
Streaming your logs to CloudWatch can help safeguard your data. For example, if your Elastic Beanstalk environment has a problem with an EC2 instance that terminates, then you can still recover your logs from CloudWatch. You can also use log rotation to protect against data loss.
Related Information
What Is Amazon CloudWatch Logs?
Troubleshooting CloudWatch Logs Integration
Streaming Elastic Beanstalk Environment Health Information to Amazon CloudWatch Logs