Commit 4fbd68c9 by QIANGLU

优化log endponit

parent be053221
...@@ -31,7 +31,10 @@ ...@@ -31,7 +31,10 @@
<artifactId>apollo-client</artifactId> <artifactId>apollo-client</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId> <artifactId>spring-boot-actuator-autoconfigure</artifactId>
......
package com.secoo.mall.logs.endpoint; package com.secoo.mall.logs.endpoint;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.LoggerContext;
import com.alibaba.fastjson.JSON;
import org.slf4j.impl.StaticLoggerBinder; import org.slf4j.impl.StaticLoggerBinder;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import java.util.LinkedHashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author qianglu * @author qianglu
...@@ -21,7 +25,11 @@ public class LogEndpoint { ...@@ -21,7 +25,11 @@ public class LogEndpoint {
List<String> result = new LinkedList<>(); List<String> result = new LinkedList<>();
LoggerContext factory = (LoggerContext) StaticLoggerBinder.getSingleton().getLoggerFactory(); LoggerContext factory = (LoggerContext) StaticLoggerBinder.getSingleton().getLoggerFactory();
List<Logger> li = factory.getLoggerList(); List<Logger> li = factory.getLoggerList();
li.forEach(logs -> result.add(logs.getName())); li.forEach(logs -> {
Map<String, Level> msg = new LinkedHashMap<>();
msg.put(logs.getName(), logs.getLevel());
result.add(JSON.toJSONString(msg));
});
return result; return result;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment