Skip to content

Commit 0dd9c71

Browse files
committed
使用log4j2记录日志
1 parent 5d82536 commit 0dd9c71

File tree

6 files changed

+104
-3
lines changed

6 files changed

+104
-3
lines changed

2.x/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@
101101
### 日志管理
102102

103103
- [Spring Boot 2.x基础教程:默认日志管理与Logback配置详解](https://blog.didispace.com/spring-boot-learning-2-8-1)
104+
- [Spring Boot 2.x基础教程:使用log4j2记录日志](https://blog.didispace.com/spring-boot-learning-2-8-2)
104105
- [Spring Boot 2.x基础教程:使用tinylog记录日志](https://blog.didispace.com/spring-boot-learning-2-8-3)
105-
- [Spring Boot 2.x基础教程:使用log4j2记录日志](https://blog.didispace.com/spring-boot-learning-2-8-3)
106+
106107

107108
### 其他内容
108109

2.x/README_zh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@
103103
### 日志管理
104104

105105
- [Spring Boot 2.x基础教程:默认日志管理与Logback配置详解](https://blog.didispace.com/spring-boot-learning-2-8-1)
106+
- [Spring Boot 2.x基础教程:使用log4j2记录日志](https://blog.didispace.com/spring-boot-learning-2-8-2)
106107
- [Spring Boot 2.x基础教程:使用tinylog记录日志](https://blog.didispace.com/spring-boot-learning-2-8-3)
107-
- [Spring Boot 2.x基础教程:使用log4j2记录日志](https://blog.didispace.com/spring-boot-learning-2-8-3)
108108

109109
### 其他内容
110110

2.x/chapter8-2/pom.xml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>org.springframework.boot</groupId>
8+
<artifactId>spring-boot-starter-parent</artifactId>
9+
<version>2.6.1</version>
10+
<relativePath/> <!-- lookup parent from repository -->
11+
</parent>
12+
13+
<groupId>com.didispace</groupId>
14+
<artifactId>chapter8-2</artifactId>
15+
<version>0.0.1-SNAPSHOT</version>
16+
<description>使用log4j2记录日志</description>
17+
18+
<properties>
19+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20+
<java.version>1.8</java.version>
21+
</properties>
22+
23+
<dependencies>
24+
<dependency>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-starter-web</artifactId>
27+
</dependency>
28+
29+
<!-- <dependency>-->
30+
<!-- <groupId>org.springframework.boot</groupId>-->
31+
<!-- <artifactId>spring-boot-starter-log4j2</artifactId>-->
32+
<!-- </dependency>-->
33+
34+
<dependency>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter-test</artifactId>
37+
<scope>test</scope>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>org.projectlombok</groupId>
42+
<artifactId>lombok</artifactId>
43+
<scope>provided</scope>
44+
</dependency>
45+
</dependencies>
46+
47+
<build>
48+
<plugins>
49+
<plugin>
50+
<groupId>org.springframework.boot</groupId>
51+
<artifactId>spring-boot-maven-plugin</artifactId>
52+
<configuration>
53+
<fork>true</fork>
54+
</configuration>
55+
</plugin>
56+
</plugins>
57+
</build>
58+
59+
</project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.didispace.chapter82;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
7+
/**
8+
* @author 程序猿DD
9+
* @version 1.0.0
10+
* @blog https://blog.didispace.com
11+
*/
12+
@Slf4j
13+
@SpringBootApplication
14+
public class Chapter82Application {
15+
16+
public static void main(String[] args) {
17+
SpringApplication.run(Chapter82Application.class, args);
18+
19+
log.error("Hello World");
20+
log.warn("Hello World");
21+
log.info("Hello World");
22+
log.debug("Hello World");
23+
log.trace("Hello World");
24+
}
25+
26+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
debug=true
2+
3+
spring.output.ansi.enabled=detect
4+
5+
logging.file.name=run.log
6+
logging.file.path=./
7+
8+
logging.level.com.didispace=debug
9+
10+
logging.logback.rollingpolicy.clean-history-on-start=false
11+
logging.logback.rollingpolicy.file-name-pattern=
12+
logging.logback.rollingpolicy.max-history=7
13+
logging.logback.rollingpolicy.max-file-size=10MB
14+
logging.logback.rollingpolicy.total-size-cap=0B

2.x/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484

8585
<!-- 日志管理 -->
8686
<module>chapter8-1</module> <!-- 8-1 默认日志管理与Logback配置详解 -->
87-
87+
<module>chapter8-2</module> <!-- 8-2 使用log4j2记录日志 -->
88+
<!-- 8-3 使用tinylog记录日志 -->
8889

8990
</modules>
9091
</project>

0 commit comments

Comments
 (0)