---
title: Logging Implementation in Spring
description: Explore logging implementation in Spring Boot, including default Logback setup, switching to Log4j 2, logging pattern layout configurations, and testing log messages.
image: https://blog.rheinwerk-computing.com/hubfs/Logging%20Implementation%20in%20Spring.png
---

[![Rheinwerk Computing Logo](https://blog.rheinwerk-computing.com/hubfs/computing_logo-header.svg)](https://blog.rheinwerk-computing.com/) [Blog](https://blog.rheinwerk-computing.com)

- Books 
    - Get an overview of our wide selection of books on every relevant computing topic. 
          - [General Computing](https://www.sap-press.com/rheinwerk-computing/general-computing/)
          - [DevOps](https://www.sap-press.com/rheinwerk-computing/devops/)
          - [Programming Languages](https://www.sap-press.com/rheinwerk-computing/programming-languages/)
          - [Security](https://www.sap-press.com/rheinwerk-computing/security/)
          - [Software Development](https://www.sap-press.com/rheinwerk-computing/software-development/)
- Book Subscription 
    - Get unlimited access to all Rheinwerk Computing books! 
          - [Programming Subscription](https://sap-press.com/subscriptions/)

[Java](https://blog.rheinwerk-computing.com/tag/java)

# Logging Implementation in Spring

![Rheinwerk Computing](https://blog.rheinwerk-computing.com/hubfs/RW-logo-300x300.png)  by [Rheinwerk Computing](https://blog.rheinwerk-computing.com/author/rheinwerk-computing)

We work in Spring Boot with SLF4J, but not with the application programming interface (API) of the actual logging provider.

 

We usually don’t notice which logging implementation is doing the actual work—that is completely abstracted by [Spring Boot](https://learning.rheinwerk-computing.com/java#spring-boot).

 

The Spring team has chosen *Logback* ([*https://logback.qos.ch*](https://logback.qos.ch)) as an implementation. Logback is the successor of the popular *Log4j 1.x* library. Logback was followed by *Log4j 2* ([*https://logging.apache.org/log4j/2.x*](https://logging.apache.org/log4j/2.x)), but the Spring team hasn’t yet moved to Log4j 2, even though the topic keeps coming up as this figure proves.

 

![Heated Discussion about Switching from Logback to Log4j 2](https://blog.rheinwerk-computing.com/hs-fs/hubfs/image-png-Oct-30-2024-11-49-09-1686-AM.png?width=1248&height=461&name=image-png-Oct-30-2024-11-49-09-1686-AM.png)

## Conversion to Log4j 2

Although Spring Boot uses Logback as a logger provider by default, Log4j 2 can easily be brought in. This is done by first taking out spring-boot-starter-logging and then including spring-boot-starter-log4j2:

 

`<dependency>`

`   <groupId>org.springframework.boot</groupId>`

`   <artifactId>spring-boot-starter-****</artifactId>`

`   <!-- remove logback -->`

`   <exclusions>`

`       <exclusion>`

`           <groupId>org.springframework.boot</groupId>`

`           <artifactId>spring-boot-starter-logging</artifactId>`

`       </exclusion>`

`       </exclusions>`

`</dependency>`

 

`<!-- add log4j2 -->`

`<dependency>`

`   <groupId>org.springframework.boot</groupId>`

`   <artifactId>spring-boot-starter-log4j2</artifactId>`

`</dependency>`

## Logging Pattern Layout

Spring configures the loggers with a pattern layout. An example output looks like this:

 

`2024-10-27T18:43:29.148+02:00 INFO 22280 --- [ main] ↩`

`c.t.s.SpringShellApplication: No active profile set.`

 

The default logging format of Spring Boot follows a specific pattern. It starts with a timestamp, followed by the log level, which, in this case, is INFO. The process ID is then displayed, followed by the thread name, which, in our case, is main. Next, the logger name is written, which is usually the same as the class name. Finally, we have the actual log message and possibly a stack trace.

 

This pattern is configurable and defined for Logback in the *defaults.xml* file. There are two patterns defined: one for console output and a separate pattern for log files. For console output, the pattern looks like this:

 

`<property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{${LOG_`

`DATEFORMAT_PATTERN:-yyyy-MM-dd'T'HH:mm:ss.SSSXXX}}){faint} %clr(${LOG_LEVEL_`

`PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([`

`%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_`

`EXCEPTION_CONVERSION_WORD:-%wEx}}"/>`

 

Let’s go through the log output with the format again in detail. The pattern in the XML file can be decomposed into the components that are shown in this table.

![Default Logger Configuration for Logback](https://blog.rheinwerk-computing.com/hs-fs/hubfs/image-png-Oct-30-2024-11-49-42-2663-AM.png?width=1152&height=873&name=image-png-Oct-30-2024-11-49-42-2663-AM.png)

 

For Log4j 2, the settings look similar.

 

## Change the Logging Configuration

Spring Boot defines a whole set of generic configuration properties that are mapped to the corresponding logger implementations. The log settings are located under the logging root element:

- **file.name:** Logging to a given file instead of the console.
- **file.path:** Path for the log file (*spring.log* by default).
- **pattern.console:** Pattern for log messages on the console.
- **pattern.file:** Pattern for log messages in the log file.

There are quite a few other things you can configure. The Spring Boot reference documentation elaborates on this.

 

## Banner

By default, after starting up, Spring Boot displays a banner. However, we disabled the banner early on by setting a configuration property. The text for the banner is built-in and comes from a Java archive, but it can be easily replaced with custom text. To define your own banner, simply create a text file named *banner.txt*, and place it directly in the source class path under *src/main/resources*.

**Tip:** There are various websites that compose text from letters, numbers, and special characters into large decorative letters. A well-known program is *FIGlet* (*www.figlet.org*). There are command-line tools and various web pages that generate a large text from a text and a chosen FIGlet font—there are dozens of them. Here’s an example of the text “Spring”:

 

o-o

|                         o

o-o    o-o    o-o    o-o    o--o

       |  |      |  |      |  |     |   |     |

o--o  O-o    o     |  o    o o--O

          |                                  |

          o                           o--o

 

The lines can be copied directly into a separate file *banner.txt*.

 

**Variables in Banner:** In the *banner.txt* file, expressions with ${…} can access configuration properties. This can be used to display certain information directly at startup, such as the title of the application (${application.title}) or even the Spring Boot version (${springboot. version}). In addition, ANSI colors can be set, such as ${Ansi.GREEN}. (For an overview, see [*http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#bootfeatures-banner*](http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#bootfeatures-banner).)

 

Spring Boot automatically detects if the console recognizes colors and sets spring.output. ansi.enabled=DETECT. This means that if the console doesn’t support colors, ANSI control codes for colors won’t be displayed. Possible assignments are ALWAYS, DETECT, and NEVER. This is one of the important differences between logging to files and logging to the console. When outputs go to files, colors are out of place and also not set.

 

That this is done by spring.main.bannermode= off. An alternative is to control the mode via SpringApplication and the setBannerMode(Banner.Mode) method.

## Logging at Start Time

When an application starts, Spring Boot logs additional output very early, for example, about the set profile. These startup outputs can be disabled. If this isn’t desired, you can set the setting via a configuration property, for example, in *application.properties*:

 

`spring.main.log-startup-info=false`

 

`Alternatively, the property can be set via code:`

 

`var app = new SpringApplication( Date4uApplication.class );`

`app.setLogStartupInfo( false );`

`app.setBannerMode( Banner.Mode.OFF );`

`app.run( args );`

## Testing Written Log Message

Logging can be tested, and Spring Boot provides a way to do this. We can test whether an application has written something to the log stream. The following example demonstrates this: the NiceGuy class has a method that writes an info message to the log stream, and the LogTest test class accesses this method:

 

`import org.assertj.core.api.Assertions;`

`import org.junit.jupiter.api.Test;`

`import org.junit.jupiter.api.extension.ExtendWith;`

`import org.slf4j.LoggerFactory;`

`import org.springframework.boot.test.system.CapturedOutput;`

`import org.springframework.boot.test.system.OutputCaptureExtension;`

`class NiceGuy {`

`   void doWhat?() {`

`       LoggerFactory.getLogger( getClass() ).info( "nice guys finish last" );`

`   }`

`}`

 

`@ExtendWith( OutputCaptureExtension.class )`

`public class LogTest {`

 

`   private NiceGuy niceGuy = new NiceGuy();`

 

`   @Test void testLog( CapturedOutput output ) {`

`       niceGuy.doWhat?();`

`       Assertions.assertThat( output.getOut() ).contains( "finish last" );`

`   }`

`}`

 

No slice test or annotation @SpringBootTest is needed for this test, just JUnit extension @ExtendWith(OutputCaptureExtension.class). Then, when we instantiate NiceGuy—usually, we would inject the component—we can call the niceGuy.doWhat? method, which should result in log output. This can be tested. A call to output.getOut() will return the log messages, and AssertJ can use contains(…) to provide an answer as to whether "finish last" is included.

 

 Editor’s note: This post has been adapted from a section of the book *[Spring Boot 3 and Spring Framework 6](https://www.amazon.com/Spring-Boot-Framework-Christian-Ullenboom/dp/1493224751?maas=maas_adg_E833057674B84459A19454B0C941B69F_afap_abs&ref_=aa_maas&tag=maas)* by Christian Ullenboom. Christian is an Oracle-certified Java programmer and has been a trainer and consultant for Java technologies and object-oriented analysis and design since 1997. 

 

This post was originally published 1/2025.

## Recommendation

[![Spring Boot 3 and Spring Framework 6](https://blog.rheinwerk-computing.com/hs-fs/hubfs/social-suggested-images/2475-Oct-11-2023-04-47-17-6521-PM-1-1-1-1-1.jpg?width=170&name=2475-Oct-11-2023-04-47-17-6521-PM-1-1-1-1-1.jpg)](https://www.amazon.com/Spring-Boot-Framework-Christian-Ullenboom/dp/1493224751?maas=maas_adg_E833057674B84459A19454B0C941B69F_afap_abs&ref_=aa_maas&tag=maas)

**Develop Java Apps Easily and Efficiently with Spring and Spring Boot!**

If you're building enterprise Java applications, this is the comprehensive guide you need — covering everything from Spring containers, dependency injection, and modules to database connectivity, RESTful services, security, and deployment. Whether you're just getting started or looking to sharpen your Spring skills, it comes packed with downloadable code examples and hands-on exercises to keep you moving.

[Learn More](https://www.amazon.com/Spring-Boot-Framework-Christian-Ullenboom/dp/1493224751?maas=maas_adg_E833057674B84459A19454B0C941B69F_afap_abs&ref_=aa_maas&tag=maas)

![Rheinwerk Computing](https://blog.rheinwerk-computing.com/hubfs/RW-logo-300x300.png)

**by [Rheinwerk Computing](https://blog.rheinwerk-computing.com/author/rheinwerk-computing)**

Rheinwerk Computing is an imprint of Rheinwerk Publishing and publishes books by leading experts in the fields of programming, administration, security, analytics, and more.

[Java](https://blog.rheinwerk-computing.com/tag/java)

[![Share on facebook](https://7528309.fs1.hubspotusercontent-na1.net/hub/7528309/hubfs/raw_assets/public/mV0_d-web-default-modules_hubspot/img/facebook-color.png?width=24&name=facebook-color.png)](https://www.facebook.com/share.php?u=https%3A%2F%2Fblog.rheinwerk-computing.com%2Flogging-implementation-in-spring%3Futm_medium%3Dsocial%26utm_source%3Dfacebook) [![Share on linkedin](https://7528302.fs1.hubspotusercontent-na1.net/hub/7528302/hubfs/raw_assets/public/mV0_d-web-default-modules_hubspot/img/linkedin-color.png?width=24&name=linkedin-color.png)](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fblog.rheinwerk-computing.com%2Flogging-implementation-in-spring%3Futm_medium%3Dsocial%26utm_source%3Dlinkedin) [![Share on twitter](https://7528304.fs1.hubspotusercontent-na1.net/hub/7528304/hubfs/raw_assets/public/mV0_d-web-default-modules_hubspot/img/twitter-color.png?width=24&name=twitter-color.png)](https://twitter.com/intent/tweet?original_referer=https%3A%2F%2Fblog.rheinwerk-computing.com%2Flogging-implementation-in-spring%3Futm_medium%3Dsocial%26utm_source%3Dtwitter&url=https%3A%2F%2Fblog.rheinwerk-computing.com%2Flogging-implementation-in-spring%3Futm_medium%3Dsocial%26utm_source%3Dtwitter&source=tweetbutton&text=) [![Share on email](https://7528311.fs1.hubspotusercontent-na1.net/hub/7528311/hubfs/raw_assets/public/mV0_d-web-default-modules_hubspot/img/email-color.png?width=24&name=email-color.png)](mailto:?subject=Check+out+https%3A%2F%2Fblog.rheinwerk-computing.com%2Flogging-implementation-in-spring%3Futm_medium%3Dsocial%26utm_source%3Demail&body=Check+out+https%3A%2F%2Fblog.rheinwerk-computing.com%2Flogging-implementation-in-spring%3Futm_medium%3Dsocial%26utm_source%3Demail)

### Comments

### Latest Blog Posts

[![Getting Started with AppArmor: Linux Security Made Simple](https://blog.rheinwerk-computing.com/hs-fs/hubfs/Getting%20Started%20with%20AppArmor_%20Linux%20Security%20Made%20Simple.jpg?height=600&name=Getting%20Started%20with%20AppArmor_%20Linux%20Security%20Made%20Simple.jpg)](https://blog.rheinwerk-computing.com/getting-started-with-apparmor-linux-security-made-simple)

[Cybersecurity](https://blog.rheinwerk-computing.com/tag/cybersecurity)

## [Getting Started with AppArmor: Linux Security Made Simple](https://blog.rheinwerk-computing.com/getting-started-with-apparmor-linux-security-made-simple)

[Read More](https://blog.rheinwerk-computing.com/getting-started-with-apparmor-linux-security-made-simple)

[![How to Set Up an H2 Database](https://blog.rheinwerk-computing.com/hs-fs/hubfs/How%20to%20Set%20Up%20an%20H2%20Database.png?height=600&name=How%20to%20Set%20Up%20an%20H2%20Database.png)](https://blog.rheinwerk-computing.com/how-to-set-up-an-h2-database)

[Java](https://blog.rheinwerk-computing.com/tag/java)

## [How to Set Up an H2 Database](https://blog.rheinwerk-computing.com/how-to-set-up-an-h2-database)

[Read More](https://blog.rheinwerk-computing.com/how-to-set-up-an-h2-database)

**Subscribe to our blog!**Get notified about future blog updates.

- <https://www.linkedin.com/showcase/rheinwerk-computing/>
- <https://www.youtube.com/channel/UChj-U-uWGM7qRlHXSFU93ew>
- <https://blog.rheinwerk-computing.com/rss.xml>

### The official Rheinwerk Computing Blog

Rheinwerk Computing is an imprint of Rheinwerk Publishing and publishes resources that will help you accelerate your computing journey. The Rheinwerk Computing Blog is designed to provide helpful, actionable information on a variety of topics, including programming, administration, security, and analytics!

### Blog Topics

- [All Topics](https://blog.rheinwerk-computing.com)
- [Programming Languages](https://blog.rheinwerk-computing.com/tag/programming-languages)
- [How To](https://blog.rheinwerk-computing.com/tag/how-to)
- [JavaScript](https://blog.rheinwerk-computing.com/tag/javascript)
- [DevOps](https://blog.rheinwerk-computing.com/tag/devops)
- [Web Development](https://blog.rheinwerk-computing.com/tag/web-development)
- [Python](https://blog.rheinwerk-computing.com/tag/python)
- [What Is?](https://blog.rheinwerk-computing.com/tag/what-is)
- [Cybersecurity](https://blog.rheinwerk-computing.com/tag/cybersecurity)
- [Software Development](https://blog.rheinwerk-computing.com/tag/software-development)
- [Java](https://blog.rheinwerk-computing.com/tag/java)

### Blog curated by

[![Rheinwerk Computing Logo](https://blog.rheinwerk-computing.com/hubfs/computing_logo-header.svg)](https://www.sap-press.com/rheinwerk-computing/) [Visit Rheinwerk Computing Store](https://www.sap-press.com/rheinwerk-computing/)

### About

- [Home](https://sap-press.com/)
- [About Us](https://sap-press.com/the-publisher/)
- [Contact](mailto:info@rheinwerk-publishing.com)
- [Legal Notes](https://sap-press.com/legal-notes/)
- [Privacy Policy](https://sap-press.com/privacy/)
- [Terms of Use](https://sap-press.com/terms/)

© 2026 Rheinwerk Publishing, Inc. | Change Privacy Options

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Rheinwerk Computing",
    "url" : "https://blog.rheinwerk-computing.com/author/rheinwerk-computing"
  },
  "dateModified" : "2026-03-13T15:53:23.836Z",
  "datePublished" : "2025-03-26T15:32:12.000Z",
  "headline" : "Logging Implementation in Spring",
  "image" : [ "https://blog.rheinwerk-computing.com/hubfs/Logging%20Implementation%20in%20Spring.png" ],
  "mainEntityOfPage" : {
    "@id" : "https://blog.rheinwerk-computing.com/logging-implementation-in-spring",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://blog.rheinwerk-computing.com/hubfs/Logo-1.jpg"
    },
    "name" : "Rheinwerk Publishing, Inc."
  }
}
```