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:
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:
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:
Similarly, the sql group contains the following loggers:
Configuring the log level for either of these groups would be applied to all group members automatically.
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.