SLF4J and Logback
On This Lesson 4 topics
The content for this lesson is written and waiting for review. The outline below shows what it covers. It will be published once it is approved.
In this lesson
log through SLF4J and configure Logback.
Planned topics
- SLF4J is the API you write against. Logback is the engine that writes the output.
- Create one logger per class:
LoggerFactory.getLogger(OrderService.class). - Use
{}placeholders, not string concatenation: the message is built only if the level is on. - Logback config (
logback.xml) has appenders (where), patterns (format), and levels (what). - Set levels per package, for example
com.shopatDEBUGand the rest atINFO.
Draft outline details
Demonstration
private static final Logger log = LoggerFactory.getLogger(OrderService.class);
log.info("Order {} placed for customer {}", orderId, customerId);Check your understanding
Why use {} and not +?
Show answer
The text is built only when that level is enabled.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.