Python 官方文档:入门教程 => 点击学习
目录1.SpringBoot使用log4j22.指定日志配置文件和日志等级3.通过springboot-actuator动态调整日志级别3.1在pom文件中引入依赖3.2在配置文件中
springboot使用的common-logging,底层兼容各种日志框架如,log4j2,slf4,logback等,默认底层使用的是logback,我们可以去除logback的依赖,引入log4j2的starter,
如下:
(此配置不限于log4j2,也适用于其他日志框架)
在resources目录下加入log4j2的xml配置文件,默认spring-boot会加载classpath下面的名为log4j2.xml,或log4j2-file.xml的日志配置文件。
也可以在spring的配置文件中指定需要加载的日志配置文件,以及动态调整各个目录的日志等级
logging:
config: classpath:log4j2.xml
level:
com.ly: debug
org.springframework : info
该参数可以通过系统参数,或启动参数,覆盖jar内的配置项。
java -jar -Dlogging.config="xxx" test.jar
java -jar test.jar --logging.config="xxx"
(适用于生产环境)
spring-boot-actuator是springboot的一个监控工具,它可以以http或JMX的方式暴露一些endPoint,内置的endpoint有 health,info,beans,loggers等。
我们可以通过loggers来动态调整日志级别,无需重启服务。
如果是想使用WEBEndPoint的话,项目必须包含web-starter相关的依赖,因为actuator 的httpEndPoint是以mvc的方式集成的。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
management:
endpoints:
web:
exposure:
include: loggers
URI默认是 /actuator+endpoint+包名
$ curl 'http://localhost:8080/actuator/loggers/com.example' -i -X POST \
-H 'Content-Type: application/JSON' \
-d '{"configuredLevel":"debug"}'
原理可以看LoggersEndPoint的实现
有个loggingApplicationListener的监听器,监听了spring的事件,读取了spring容器中的日志配置,进行了日志的初始化。
到此这篇关于springboot动态调整日志级别的文章就介绍到这了,更多相关springboot调整日志级别内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: springboot动态调整日志级别的操作大全
本文链接: https://www.lsjlt.com/news/154482.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0