Commit cf68a533 by QIANGLU

Merge branch 'dev'

parents 6b053ac5 71f27b11
......@@ -31,6 +31,20 @@
<artifactId>apollo-client</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.5</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.secoo.mall.logs.boot;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.util.StringUtils;
/**
* 用于启动后数据加载
* @author qianglu
*/
public class MatrixApplicationRunner implements ApplicationRunner {
private String url;
public MatrixApplicationRunner(String url) {
if(!StringUtils.isEmpty(url)){
this.url = url;
}
}
@Override
public void run(ApplicationArguments args) throws Exception {
}
}
......@@ -5,12 +5,16 @@ import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfig;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import com.ctrip.framework.apollo.spring.boot.ApolloAutoConfiguration;
import com.secoo.mall.logs.endpoint.LogEndpoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.logging.LogLevel;
import org.springframework.boot.logging.LoggingSystem;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
......@@ -19,6 +23,7 @@ import java.util.Set;
/**
* 用于提供动态日志切换
*
* @author qianglu
*/
@Configuration
......@@ -44,11 +49,11 @@ public class MatrixLogListenerConfiguration implements InitializingBean {
private void refreshLoggingLevels() {
Set<String> keyNames = config.getPropertyNames();
for (String key : keyNames) {
if (StringUtils.startsWithIgnoreCase(key,LOGGER_TAG)) {
if (StringUtils.startsWithIgnoreCase(key, LOGGER_TAG)) {
String strLevel = config.getProperty(key, "info");
LogLevel level = LogLevel.valueOf(strLevel.toUpperCase());
loggingSystem.setLogLevel(key.replace(LOGGER_TAG, ""), level);
logger.info("update class {} logger level to {}", key, strLevel);
logger.info("update class {} logger level to {}" , key, strLevel);
}
}
}
......@@ -58,4 +63,11 @@ public class MatrixLogListenerConfiguration implements InitializingBean {
public void afterPropertiesSet() throws Exception {
refreshLoggingLevels();
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public LogEndpoint logEndpoint() {
return new LogEndpoint();
}
}
package com.secoo.mall.logs.endpoint;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import org.slf4j.impl.StaticLoggerBinder;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import java.util.LinkedList;
import java.util.List;
/**
* @author qianglu
*/
@Endpoint(id = "matrixlog")
public class LogEndpoint {
@ReadOperation
public List<String> matrixlog() {
List<String> result = new LinkedList<>();
LoggerContext factory = (LoggerContext) StaticLoggerBinder.getSingleton().getLoggerFactory();
List<Logger> li = factory.getLoggerList();
li.forEach(logs -> result.add(logs.getName()));
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