Spring Boot
Capstone – Article 14: Logging, Monitoring & Actuator (Expense Tracker)
By Utility Zone · 2026-01-27T18:33:43.506442
1. Introduction
A production system is not complete if you cannot observe it.
Logging and monitoring help you:
- Debug issues quickly
- Understand system behavior
- Detect failures early
In this article, we will make the Expense Tracker observable and production-ready.
2. Logging Strategy
Spring Boot uses:
- SLF4J (API)
- Logback (implementation)
Good logging answers:
- What happened?
- When did it happen?
- Why did it fail?
3. Adding Loggers in Code
Example in service layer:
private static final Logger log =
LoggerFactory.getLogger(ExpenseService.class);
public ExpenseResponse createExpense(ExpenseRequest request) {
log.info("Creating expense for logged-in user");
ExpenseResponse response = saveExpense(request);
log.debug("Expense created with id {}", response.getId());
return response;
}
Guidelines:
✔ Use INFO for business flow
✔ DEBUG for details
✔ ERROR for failures
4. Configuring Log Levels
In application.properties:
logging.level.root=INFO
logging.level.com.example.expensetracker=DEBUG
This:
- Keeps logs readable
- Enables debugging for your code only
5. Log Format
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %-5level %logger - %msg%n
Readable logs save time during incidents.
6. Introducing Spring Boot Actuator
Actuator provides:
- Health checks
- Metrics
- App info
- Environment visibility
Add dependency (if not already added):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
7. Important Actuator Endpoints
| Endpoint | Purpose |
|---|---|
/actuator/health | App health |
/actuator/info | App info |
/actuator/metrics | Metrics |
/actuator/env | Environment |
8. Exposing Actuator Endpoints
management.endpoints.web.exposure.include=health,info,metrics
Test:
GET /actuator/health
9. Custom Health Indicator
@Component
public class DatabaseHealthIndicator implements HealthIndicator {
@Override
public Health health() {
boolean dbUp = true; // simulate DB check
if (dbUp) {
return Health.up().build();
}
return Health.down().withDetail("Database", "Not reachable").build();
}
}
Custom health checks are used heavily in production.
10. Securing Actuator Endpoints
Never expose sensitive endpoints publicly.
management.endpoints.web.exposure.include=health
Secure others using Spring Security.
11. Observing Metrics
Example metric:
/actuator/metrics/jvm.memory.used
Useful for:
- Memory leaks
- Performance tuning
12. Common Logging & Monitoring Mistakes
❌ Logging sensitive data
❌ Excessive DEBUG logs in prod
❌ No health checks
❌ Ignoring logs until failure
13. Git Commit (Important)
git add .
git commit -m "Add logging and actuator monitoring"
14. What You Should Have Now
At this point:
- Logs are structured
- Health endpoints work
- Metrics are available
- App is observable
15. What’s Next?
➡ Capstone – Article 15: Dockerization & Deployment
- Dockerfile
- Containerization
- Cloud deployment
Type Next when you’re ready 🚀