由于线上运行的项目,出现问题 想看下sql的参数,或者一些框架的debug日志。需要把日志界别从info-->debug。需要动态实时的修改日志界别。
只要类: LoggersEndpoint
maven 依赖:
org.springframework.boot spring-boot-starter-actuator
springboot1.x ===================yml配置 ========================================================== server: port: 8083 context-path: / endpoints: enabled: true management: security: enabled: false ====================默认级别 INFO ========================================================== logLevel: '{"com.xx.elk":"INFO","com.xxx.mapper":"INFO"}' ====================代码使用=========================================================== @Autowired private LoggersEndpoint loggersEndpoint; private static SortedMaplogLevel; @NacosValue(value = "#{${hjd.nacos.logLevel}}", autoRefreshed = true) public void setLogLevel(SortedMap logLevel) { HjdApolloConfig.logLevel = logLevel; //加载配置参数时 对应未初始化 if (loggersEndpoint == null) { return; } logLevel.forEach((k, v) -> loggersEndpoint.setLogLevel(k, LogLevel.valueOf(v))); }
浏览器访问: http://localhost:8086/dyj/loggers 可以看到项目中所有的日志配置
=====================通过nacos/apollo动态修改参数=========================================== logLevel: '{"com.xx.elk":"DEBUG","com.xxx.mapper":"DEBUG"}'
得到sql执行参数
springboot2.x的配置 management: endpoints: web: exposure: include: "*" base-path: /actuator loggersEndpoint.configureLogLevel(xxx,xxxx);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)