Generic Top

I just announced the new Learn Spring course, focused on the fundamentals of Spring 5 and Spring Boot 2:

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

Generic bottom

I just announced the new Learn Spring course, focused on the fundamentals of Spring 5 and Spring Boot 2:

>> CHECK OUT THE COURSE
Comments are closed on this article!