Skip to content
Ameen Abozaid
In reviewJNR-006-L02

SLF4J and Logback

  • Lesson 2 of 7
  • 11 min read
  • Junior
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.shop at DEBUG and the rest at INFO.
Draft outline details

Demonstration

java
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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.