“Spring Boot 日志设计结构”的版本间的差异
跳到导航
跳到搜索
Jihongchang(讨论 | 贡献) (建立内容为“https://www.bilibili.com/video/BV1iJ411H74S?p=36”的新页面) |
Jihongchang(讨论 | 贡献) (→依赖关系图) |
||
(未显示同一用户的2个中间版本) | |||
第1行: | 第1行: | ||
https://www.bilibili.com/video/BV1iJ411H74S?p=36 | https://www.bilibili.com/video/BV1iJ411H74S?p=36 | ||
+ | |||
+ | === pom.xml === | ||
+ | <syntaxhighlight lang="xml"> | ||
+ | <?xml version="1.0" encoding="UTF-8"?> | ||
+ | <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
+ | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
+ | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
+ | <modelVersion>4.0.0</modelVersion> | ||
+ | |||
+ | <parent> | ||
+ | <artifactId>spring-boot-starter-parent</artifactId> | ||
+ | <groupId>org.springframework.boot</groupId> | ||
+ | <version>2.2.2.RELEASE</version> | ||
+ | </parent> | ||
+ | |||
+ | <groupId>io.github.jihch</groupId> | ||
+ | <artifactId>spring-boot-log</artifactId> | ||
+ | <version>1.0-SNAPSHOT</version> | ||
+ | |||
+ | <properties> | ||
+ | <maven.compiler.source>8</maven.compiler.source> | ||
+ | <maven.compiler.target>8</maven.compiler.target> | ||
+ | </properties> | ||
+ | |||
+ | <dependencies> | ||
+ | <dependency> | ||
+ | <groupId>org.springframework.boot</groupId> | ||
+ | <artifactId>spring-boot-starter-web</artifactId> | ||
+ | </dependency> | ||
+ | |||
+ | <dependency> | ||
+ | <groupId>org.springframework.boot</groupId> | ||
+ | <artifactId>spring-boot-starter-test</artifactId> | ||
+ | <scope>test</scope> | ||
+ | <exclusions> | ||
+ | <exclusion> | ||
+ | <groupId>org.junit.vintage</groupId> | ||
+ | <artifactId>junit-vintage-engine</artifactId> | ||
+ | </exclusion> | ||
+ | </exclusions> | ||
+ | </dependency> | ||
+ | </dependencies> | ||
+ | |||
+ | </project> | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ==== 依赖关系图 ==== | ||
+ | {| class="wikitable" | ||
+ | ! | ||
+ | ! colspan="3" |spring-boot-starter-web | ||
+ | |- | ||
+ | ! | ||
+ | ! colspan="3" |spring-boot-starter | ||
+ | |- | ||
+ | ! | ||
+ | ! colspan="3" |spring-boot-starter-logging | ||
+ | |- | ||
+ | ! | ||
+ | !jul-to-slf4j(桥接器) | ||
+ | !log4j-to-slf4j(桥接器) | ||
+ | !logback-classic | ||
+ | |- | ||
+ | !日志门面 | ||
+ | ! colspan="3" |slf4j-api | ||
+ | |- | ||
+ | !日志实现 | ||
+ | !JUL | ||
+ | !Log4j | ||
+ | !Logback | ||
+ | |} | ||
+ | |||
+ | === 总结 === | ||
+ | |||
+ | # Spring Boot 底层默认使用 Logback 作为日志实现 | ||
+ | # 使用了 SLF4J 作为日志门面 | ||
+ | # 将 JUL 也转换成 SLF4J | ||
+ | # 也可以使用 Log4j 2 作为日志门面,但是最终也是通过 SLF4J 调用 Logback |
2023年2月28日 (二) 09:58的最新版本
https://www.bilibili.com/video/BV1iJ411H74S?p=36
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.2.2.RELEASE</version>
</parent>
<groupId>io.github.jihch</groupId>
<artifactId>spring-boot-log</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
依赖关系图
spring-boot-starter-web | |||
---|---|---|---|
spring-boot-starter | |||
spring-boot-starter-logging | |||
jul-to-slf4j(桥接器) | log4j-to-slf4j(桥接器) | logback-classic | |
日志门面 | slf4j-api | ||
日志实现 | JUL | Log4j | Logback |
总结
- Spring Boot 底层默认使用 Logback 作为日志实现
- 使用了 SLF4J 作为日志门面
- 将 JUL 也转换成 SLF4J
- 也可以使用 Log4j 2 作为日志门面,但是最终也是通过 SLF4J 调用 Logback