Spring Boot Actuator & Logging (Beginner Guide)
Monitor and debug production Spring Boot apps: Actuator health and metrics endpoints, proper logging with @Slf4j and log levels, and configuring output per environment.
Building an app is one thing; running it reliably in production is another. When your app is live, you need to answer questions like "is it healthy right now?" and "what went wrong at 3am?" The tools for this are Actuator (health & metrics) and logging — the eyes and ears of a production application. This lesson kicks off the "production & deployment" part of the roadmap.
Spring Boot Actuator: your app's dashboard
Actuator adds ready-made monitoring endpoints to your app — no code required. With one dependency, you get URLs that report your app's health, metrics, and configuration. It's how you (and your monitoring tools) check that a live app is behaving. Add the starter:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
The most useful endpoint: /health
Visit /actuator/health and your app reports whether it (and things like its database connection) is up:
GET /actuator/health
{ "status": "UP" } // the app is healthy
This tiny endpoint is hugely important: load balancers, container orchestrators (like Kubernetes), and uptime monitors ping it constantly to know if your app is alive. If it ever returns DOWN, alerts fire. Other handy endpoints include /actuator/metrics (memory, CPU, request counts) and /actuator/info (app details).
/health publicly. If you enable more, protect them behind authentication (see the security lesson). You control what's exposed with management.endpoints.web.exposure.include in your config — expose deliberately, not everything.
Logging: what your app tells you
Logs are the running diary of your application — a record of what it did and when. When something breaks in production, logs are usually how you find out why. The great news: Spring Boot includes a logging system (Logback) out of the box, ready to use.
Writing logs the right way
Don't use System.out.println for real applications — use a proper logger. It gives you severity levels, timestamps, and control over output. With Lombok's @Slf4j, it's one annotation:
@Service @Slf4j // Lombok creates a 'log' object for you public class UserService { public User register(User user) { log.info("Registering user: {}", user.getEmail()); try { return repo.save(user); } catch (Exception e) { log.error("Failed to register {}", user.getEmail(), e); throw e; } } }
Note the {} placeholders — the logger fills them in efficiently, which is cleaner and faster than string concatenation.
The log levels (from quietest to loudest)
| Level | Use for… |
|---|---|
ERROR |
something failed and needs attention |
WARN |
something odd but not fatal |
INFO |
normal notable events (default level) |
DEBUG / TRACE |
detailed diagnostics (dev only) |
You set the level in config, so you can run quietly (INFO) in production and verbosely (DEBUG) when hunting a bug — without changing code:
logging:
level:
com.myapp: DEBUG # verbose logs for your own code
org.springframework: WARN
Early on, I debugged everything with System.out.println and then had to hunt down and delete all those lines later — a mess. Switching to a proper logger with levels changed how I work: I can leave log.debug statements in permanently and just turn them on when I need them. In production, good logs are often the only window into what happened during an incident — this website's logs are what I reach for first whenever something misbehaves, and Actuator's /health is what tells me at a glance that everything's running. Treat logging and monitoring as features, not afterthoughts, and your future self (debugging at 3am) will thank you.
Key takeaways
- Actuator adds monitoring endpoints;
/actuator/healthreports if your app isUP— vital for load balancers and uptime checks. - Expose Actuator endpoints deliberately and protect sensitive ones behind authentication.
- Use a proper logger (
@Slf4j), notSystem.out.println; log with{}placeholders. - Log levels (ERROR/WARN/INFO/DEBUG) are configurable per environment — quiet in prod, verbose when debugging.
← Previous: Spring Lesson 12 — Spring Boot with PostgreSQL
Next: Spring Lesson 14 — Caching →
↑ Back to the Spring Boot roadmap