Exclude Springboot Specifies the log framework
Springboot comes with its own logback logging framework and other dependencies in your project may have logging frameworks, so you need to disable other logging frameworks globally in Gradle
configurations.all {
exclude group:'org.springframework.boot', module: 'spring-boot-starter-logging'
exclude module: 'logback-classic'
exclude module: 'logback-core'
}
Copy the code
There are two common ways to exclude
Method 1
Exclude is stored in the same file as dependencies if build.gradle does not include dependencies
Remove front:Removed:
Way 2
If build.gradle is a sub-projectSettings. gradle has rootProject and includes multiple projects
rootProject.name = 'gradletest'
include 'app'
include 'module1'
include 'module2'
Copy the code
Exclude then needs to be placed in the subprojects block, and it will apply to all of the subprojects (which together make your project)
Configurations. All {exclude group:' org.springFramework. boot', module: 'spring-boot-starter-logging' exclude module: 'logback-classic' exclude module: 'logback-core' } }Copy the code
Introduce log4j2 dependencies
If the springboot project inherits spring-boot-starter-parent and uses the starter dependency, the log4j2 dependency can be used without the dependency version number
compile 'org.springframework.boot:spring-boot-starter-log4j2'
Copy the code
Otherwise, add the dependent version number
The compile 'org. Springframework. The boot: spring - the boot - starter - log4j2:2.4.0'Copy the code
Add the log4j2-spring. XML file
Add the log4j2 configuration file to the appropriate resource in the project
If you have custom file names (including log4j2.xml), you need to configure them in application.yml
logging:
config: xxxx.xml
Copy the code
The default name is log4j2-spring.xml, which requires no additional configuration in application.yml
For details on how to configure log4j2-spring. XML, please refer to my other article
The log4j2 configuration file is not fully parsed