Course – LS – All

Get started with Spring and Spring Boot, through the Learn Spring course:

>> CHECK OUT THE COURSE

1. Overview

Spring Boot provides many auto-configurations to facilitate writing enterprise applications. However, it was always a bit cumbersome to apply the same logging configuration to a set of loggers.

In this quick tutorial, we’re going to see how the new log groups feature is going to fix this issue.

2. Log Groups

As of Spring Boot 2.1, it’s possible to group multiple loggers together and then configure them at the same time.

In order to use this feature, first, we should declare a group via the logging.group configuration property:

logging.group.rest=com.baeldung.web,org.springframework.web,org.springframework.http

Here we’re creating a group named rest containing three different logger names. Grouping loggers is as simple as separating their respective logger names with a comma.

Then we can apply configurations to all loggers in a group at once. For instance, here we’re changing the log level for this group to debug:

logging.level.rest=DEBUG

As a result, Spring Boot applies the same log level for all three group members.

2.1. Built-in Groups

By default, Spring Boot comes with two built-in groups: sql and web. 

Currently, the web group consists of the following loggers:

  • org.springframework.core.codec
  • org.springframework.http
  • org.springframework.web
  • org.springframework.boot.actuate.endpoint.web
  • org.springframework.boot.web.servlet.ServletContextInitializerBeans

Similarly, the sql group contains the following loggers:

  • org.springframework.jdbc.core
  • org.hibernate.SQL
  • org.jooq.tools.LoggerListener

Configuring the log level for either of these groups would be applied to all group members automatically.

3. Conclusion

In this short article, we familiarized ourselves with the log groups in Spring Boot. This feature enables us to apply a log configuration to a set of loggers at once.

As usual, the sample code is available over on GitHub.

Course – LS – All

Get started with Spring and Spring Boot, through the Learn Spring course:

>> CHECK OUT THE COURSE
res – REST with Spring (eBook) (everywhere)
Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.