SpringBoot动态修改日志级别

SpringBoot1.5新特性

目录

  1. 安装依赖
  2. 测试显示日志级别
  3. 测试修改日志级别
1.在pom中添加依赖

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.1.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>
2.开始测试

http://localhost:8080/loggers

服务:

s.b.a.e.m.MvcEndpointSecurityInterceptor : Full authentication is required to access actuator endpoints. Consider adding Spring Security or set 'management.security.enabled' to false.

需要手动设置management.security.enabled=false

  • 继续测试

http://localhost:8080/loggers

服务返回:

{
levels: [
"OFF",
"ERROR",
"WARN",
"INFO",
"DEBUG",
"TRACE"
],
loggers: {
ROOT: {
configuredLevel: "INFO",
effectiveLevel: "INFO"
},
elephant: {
configuredLevel: "DEBUG",
effectiveLevel: "DEBUG"
},
...

3.修改日志级别

POST请求
http://localhost:8080/loggers/{elephant}

{}中根据/loggers方法返回的目录级别添加

eg:

我要修改elephant.zybank.rest目录下级别

就使用下面请求方法

http://localhost:8080/loggers/elephant.zybank.rest

请求体中使用json

{
    "configuredLevel": "DEBUG"
}

登录服务器

curl -H "Content-Type: application/json" -X POST --data 
'
{
    "configuredLevel": "DEBUG"
}
' 
http://localhost:8080/loggers/elephant.zybank.rest
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 137,086评论 19 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,338评论 6 342
  • 3月25日,胡炜老师如约而至中宇恒通。其实实在不忍心打扰胡老师的紧张天伦时间,简单沟通后胡老师爽快答应了。中宇恒通...
    尚轩堂主阅读 807评论 0 3
  • 昨天加了扇贝的21天早起计划。 于是今早就挣扎着,摁开手机,半梦半醒里开始背单词,背到完全清醒。希望这样能对抗懒惰...
    Leathy阅读 178评论 2 1
  • 我一个同事曾经说过这样一句话,我们每天24小时,除去休息的时间,工作占用的时间基本要占用1/2,而我们同事相处的时...
    兰风蕙露阅读 720评论 10 12

友情链接更多精彩内容