SLF4J + Loki Integration
Spring Boot App
↓
SLF4J API
↓
Logback
↓
Log File / Stdout
↓
Promtail
↓
Loki
↓
Grafana
| SLF4J |
Loki |
| Standard logging API |
Centralized log storage |
| Framework-agnostic |
Cost-efficient |
| Clean code |
Easy querying |
| Structured logging support |
Native Grafana integration |
SLF4J (Simple Logging Facade for Java)
- A logging abstraction, not a logging implementation.
- Defines common logging APIs, but the real logging is done by an underlying framework.
- Think of it as an interface:
- Let code depend on one API
- Can switch logging implementations easily
| Implementation |
Usage |
| Logback |
Default in Spring Boot |
| Log4j2 |
High performance |
| JUL |
Built-in Java logging |
Flow
Application Code
↓
SLF4J API
↓
Logging Implementation (Logback / Log4j2 / JUL)
↓
Console / File / External System
Logging level