First, brief
Springboot itself provides default profiles for SLF4J, log4j (including log4j2), Logback, and in the default settings, Springboot is to print log information only in the console, not output to the log file.
In dependent Spring-boot-starter-web, the dependency of Logback is included, that is, if <artifactid>spring-boot-starter-web</artifactid is referenced , the use of the self-logback;
If you do not want to use the logback of the Springboot band, you can exclude logback when referencing dependencies;
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions><!--Remove logging from the default configuration <exclusion> <groupId>org.springframework.boot</groupId> <artifactId> spring-boot-starter-logging</artifactid> </exclusion> </exclusions> </ Dependency> <dependency> <!--introducing LOG4J2 dependencies or other log components-- <groupId> Org.springframework.boot</groupid> <artifactId>spring-boot-starter-log4j2</artifactId> </dependency> </dependencies>
Ii. using a custom log component
Springboot supports the use of custom log components and profiles: Excludes dependencies on the default logging framework, and introduces dependencies on the log components used;
The configuration file is named Log4j2-spring.xml or Log4j2.xml (others, such as Logback-spring.xml or Logback.xml), and is recommended in xxx-spring.xml form. This eliminates the need for APPLICATION.YML configuration;
Log components for Springboot