Spring boot动态修改日志级别的方法
小魏的博客 人气:0一、前言
我们经常会遇到业务想看debug日志的问题,但是debug日志频繁打印会对日志查看有影响,且日志多对系统也会有一定的压力,因此,如果可以在需要的时候动态临时调整下日志的级别则是比较完美的,spring boot已经支持这种功能。
二、Spring boot 2.1调整方式
1、查看当前应用各包/类的日志级别
由于引入了很多其它的组件,spring boot支持对不同组件精细化调整日志级别
http://localhost:7011/actuator/loggers
{ "levels": [ "OFF", "ERROR", "WARN", "INFO", "DEBUG", "TRACE" ], "loggers": { "ROOT": { "configuredLevel": "DEBUG", "effectiveLevel": "DEBUG" }, "com": { "configuredLevel": null, "effectiveLevel": "DEBUG" }, "com.alibaba": { "configuredLevel": null, "effectiveLevel": "DEBUG" }, "com.alibaba.druid": { "configuredLevel": null, "effectiveLevel": "DEBUG" }, "com.alibaba.druid.pool": { "configuredLevel": null, "effectiveLevel": "DEBUG" }, "com.alibaba.druid.pool.DruidAbstractDataSource": { "configuredLevel": null, "effectiveLevel": "DEBUG" }, "com.alibaba.druid.pool.DruidConnectionHolder": { "configuredLevel": null, "effectiveLevel": "DEBUG" }, "com.alibaba.druid.pool.DruidDataSource": { "configuredLevel": null, "effectiveLevel": "DEBUG" }, "com.alibaba.druid.pool.DruidDataSourceStatLoggerImpl": { "configuredLevel": null, "effectiveLevel": "DEBUG" }, // ...省略 } }
2、查看指定包/类日志详情
http://localhost:7011/actuator/loggers/com.alibaba.druid
{ "configuredLevel": null, "effectiveLevel": "INFO" }
3、动态修改日志级别
再次查看日志级别如下,可见修改成功:
三、Spring boot 1.5 调整方式
URL不一样
查看日志级别:
参考资料:
加载全部内容