Configuring Logging
After a long configuration recipe on building a Spring 5 MVC application, let us discuss how to enable logging using Spring Boot 2.0
Getting started
Open ch09
again and create and add the following @Controller
that utilizes thread pools generated by TaskExecutor
.
How to do it...
If logging and auditing can be enabled in a ground-up Spring 5 application, it is easier to integrate a logging mechanism in Spring Boot. Follow these steps:
- Create the following packages that will be utilized in the succeeding recipes:
org.packt.spring.boot.controller
org.packt.spring.boot.dao
org.packt.spring.boot.service
- Since Spring Boot 2.0 directly supports
Logback
andSL4J
with fewer configurations, create the followinglogback.xml
insidesrc/main/resources
. Assign a separate logger to each package above wherein each has its ownLevel
value. Also, utilize two appenders, namelych.qos.logback.core.ConsoleAppender
to log all the messages in Tomcat'sstdout.log
andch.qos.logback.core.FileAppender
...