SpringBoot-日志系统

释放双眼,带上耳机,听听看~!

官方文档: 

https://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html\#howto-configure-logback-for-logging

通过看文档整理以下几点:

1.Spring Boot 通过引入 spring-boot-starter-web 模块即可引入日志相关依赖包。

2.Spring Boot 根据类路径下的相关日志框架的依赖包去自动构建日志系统。首选日志框架是 Logback。 

**83.1 Configure Logback for Logging **


1
2
3
4
5
6
1<?xml version="1.0" encoding="UTF-8"?>
2<configuration>
3   <include resource="org/springframework/boot/logging/logback/base.xml"/>
4   <logger name="org.springframework.web" level="DEBUG"/>
5</configuration>
6

83.1.1 Configure Logback for File-only Output


1
2
3
4
5
6
7
8
9
10
1<?xml version="1.0" encoding="UTF-8"?>
2<configuration>
3   <include resource="org/springframework/boot/logging/logback/defaults.xml" />
4   <property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}"/>
5   <include resource="org/springframework/boot/logging/logback/file-appender.xml" />
6   <root level="INFO">
7       <appender-ref ref="FILE" />
8   </root>
9</configuration>
10

 Demo

在 src/main/resource 下创建文件 logback-spring.xml


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
1<?xml version="1.0" encoding="UTF-8"?>
2<configuration>
3    <include resource="org/springframework/boot/logging/logback/defaults.xml" />
4
5    <property name="LOG_FILE" value="d:/log/my.log"/>
6
7    <include resource="org/springframework/boot/logging/logback/console-appender.xml" />
8    <include resource="org/springframework/boot/logging/logback/file-appender.xml" />
9
10    <root level="INFO">
11        <appender-ref ref="CONSOLE" />
12        <appender-ref ref="FILE" />
13    </root>
14
15    <logger name="org.springframework.web" level="INFO"/>
16</configuration>
17

相关技术点

1.可以设置不同功能模块的日志级别


1
2
3
1logging.level.org.springframework.web=DEBUG
2logging.level.org.hibernate=ERROR
3

2.可以更改日志配置文件的存储位置


1
2
1logging.config=classpath:logback-spring.xml
2

3.源码切入点


1
2
1LoggingApplicationListener
2

 

 

给TA打赏
共{{data.count}}人
人已打赏
安全技术

java千万级别数据生成文件思路和优化

2022-1-11 12:36:11

安全运维

MySQL数据库优化(二)——MySQL事务

2021-12-11 11:36:11

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索