Spring Logging

Logback Setup

To use Logback as logging backend, we need to add the logback dependency in our pom.xml and create a logback.xml file in the resources folder. Once that is created, you can annotate your classes with @Slf4j and log with log.<level>(Message);




<?xml version="1.0" encoding="UTF-8"?>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            %d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n

    <logger name="org.springframework" level="debug" additivity="false">
        <appender-ref ref="STDOUT" />

    <logger name="com.foo.bar" level="debug" additivity="false">
        <appender-ref ref="STDOUT" />

    <root level="error">
        <appender-ref ref="STDOUT" />



public class Broker {

    log.info("Something happened.")