Logging and Monitoring for Spring Boot on Elastic Beanstalk¶
This tutorial explains how to combine Spring Boot logging, Elastic Beanstalk log collection, CloudWatch Logs streaming, and health visibility. The goal is to keep request diagnostics centralized while preserving application-level structure through Logback.
Prerequisites¶
- Running Java Elastic Beanstalk environment.
- Familiarity with
eb logs, environment health, and Spring Boot basics. - IAM permissions for CloudWatch Logs and CloudWatch metrics.
What You'll Build¶
You will build:
- Console logging formatted for CloudWatch ingestion.
- Elastic Beanstalk log streaming to CloudWatch Logs.
- Health visibility through
/healthand environment monitoring.
flowchart LR
A[Spring Boot Logback] --> B[stdout and stderr]
B --> C[Elastic Beanstalk Log Files]
C --> D[CloudWatch Logs]
E[/health Endpoint] --> F[Enhanced Health]
F --> G[Elastic Beanstalk Console] Steps¶
- Start with Spring Boot console logging so Elastic Beanstalk can collect it.
logging.level.root=INFO
logging.pattern.console=%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX} %-5level [%thread] %logger{36} - %msg%n
management.endpoints.web.exposure.include=health,info
- Add a basic
logback-spring.xmlfor structured fields.
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>{"timestamp":"%date{ISO8601}","level":"%level","logger":"%logger{36}","message":"%msg"}%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
</configuration>
- Enable log streaming to CloudWatch Logs.
option_settings:
aws:elasticbeanstalk:cloudwatch:logs:
StreamLogs: true
DeleteOnTerminate: false
RetentionInDays: 14
- Keep the environment health check path on
/health.
- Review logs from the CLI.
eb logs --all
aws logs describe-log-groups --log-group-name-prefix "/aws/elasticbeanstalk" --region "$REGION"
- Inspect health and events.
Verification¶
Use these checks after enabling monitoring:
eb logs --all
aws logs tail "/aws/elasticbeanstalk/$ENV_NAME/var/log/web.stdout.log" --follow --region "$REGION"
curl --verbose "http://$CNAME/health"
Expected outcomes:
- Spring Boot logs appear in Elastic Beanstalk and CloudWatch Logs.
- The environment health check remains green.
- Structured console output is readable in CloudWatch Logs.
- Environment events help correlate deployments and incidents.