Spring Boot 2动态修改日志级别

添加依赖:


    org.springframework.boot
    spring-boot-starter-web


    org.springframework.boot
    spring-boot-starter-actuator

添加配置yml:

#### SpringBoot Actuator 组件提供动态修改日志打印级别功能
management:
  endpoints:
    web:
      exposure:
        include: 'loggers'

访问地址:

http://localhost:8080/actuator/loggers

访问上面ip地址,可以发现所有日志打印类

动态调用地址,修改日志级别,例如:

http://localhost:8080/actuator/loggers/com.tuantuan.web.controller.sys.LoginController

 发现日志级别为:info

然后模仿调用:如下图所示

Spring Boot 2动态修改日志级别_第1张图片

再访问地址:

http://localhost:8080/actuator/loggers/com.tuantuan.web.controller.sys.LoginController

 发现日志级被改为debug了。

现在的日志打印,这个类就为debug模式了。

你可能感兴趣的:(springboot)