Sample Logback Configuration for Spring Boot Profile Based Logging

We would want different logging configurations for different profiles in Spring Boot, like in local running we would just want console logging and for production, we would want file logging with support for rolling the log files daily.

I came up with a sample logback configuration which I use in all my applications. Create a file named logback-spring.xml in src/main/resources with the following content:

<?xml version="1.0" encoding="UTF-8"?>
  <include resource="org/springframework/boot/logging/logback/defaults.xml" />
  <property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${}}/}spring.log}"/>
  <include resource="org/springframework/boot/logging/logback/console-appender.xml" />

  <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">

  <springProfile name="local">
    <root level="INFO">
      <appender-ref ref="CONSOLE" />
      <appender-ref ref="FILE" />
  <springProfile name="test,prod">
    <root level="INFO">
      <appender-ref ref="FILE" />


We are using the default console appender which is provided by Spring Boot but providing our own daily rolling based file appender. I have mostly copied the base.xml and updated it to meet my needs.

Categories: Java, Spring, Spring Boot

Tags: , ,

1 reply


  1. This Month in Spring - September 6, 2018 - Tony Pagliocco

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: