Commit 2a0ecb83 authored by yanzg's avatar yanzg

修复等待时间

parent 669948f1
package com.yanzuoguang.cloud.aop.log;
import java.util.List;
/**
* 日志过滤
*
* @author 颜佐光
*/
public interface LogFilter {
/**
* 是否排除,排除后将不会再次过滤
*
* @param keys 关键字
* @return 是否排除
*/
boolean logExpect(List<String> keys);
/**
* 过滤日志
*
* @param keys 关键字
* @return 是否过滤
*/
boolean logFilter(List<String> keys);
}
package com.yanzuoguang.cloud.aop.log;
import com.yanzuoguang.cloud.CloudConfig;
import com.yanzuoguang.util.helper.StringHelper;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 日志默认过滤
*
* @author 颜佐光
*/
@Component
public class LogFilterDefault implements LogFilter {
private final CloudConfig cloudConfig;
public LogFilterDefault(CloudConfig cloudConfig) {
this.cloudConfig = cloudConfig;
}
@Override
public boolean logExpect(List<String> keys) {
if (!StringHelper.isEmpty(this.cloudConfig.getLogNotFilter())) {
for (String key : keys) {
if (StringHelper.isEmpty(key)) {
continue;
}
if (key.toLowerCase().matches(this.cloudConfig.getLogNotFilter())) {
return true;
}
}
}
return false;
}
@Override
public boolean logFilter(List<String> keys) {
if (!StringHelper.isEmpty(this.cloudConfig.getLogFilter())) {
for (String key : keys) {
if (StringHelper.isEmpty(key)) {
continue;
}
if (key.toLowerCase().matches(this.cloudConfig.getLogFilter())) {
return true;
}
}
}
return false;
}
}
...@@ -9,10 +9,7 @@ import com.yanzuoguang.util.vo.LogVo; ...@@ -9,10 +9,7 @@ import com.yanzuoguang.util.vo.LogVo;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/** /**
...@@ -27,6 +24,7 @@ public class LogLocal implements ThreadNext.Next, InitializingBean { ...@@ -27,6 +24,7 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
*/ */
private final LogBase logBase; private final LogBase logBase;
private final CloudConfig cloudConfig; private final CloudConfig cloudConfig;
private final List<LogFilter> logFilters;
/** /**
* 超时状态 * 超时状态
*/ */
...@@ -37,9 +35,10 @@ public class LogLocal implements ThreadNext.Next, InitializingBean { ...@@ -37,9 +35,10 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
*/ */
protected volatile Map<String, Timeout<LogVo>> cache = new ConcurrentHashMap<>(); protected volatile Map<String, Timeout<LogVo>> cache = new ConcurrentHashMap<>();
public LogLocal(LogBase logBase, CloudConfig cloudConfig) { public LogLocal(LogBase logBase, CloudConfig cloudConfig, List<LogFilter> logFilters) {
this.logBase = logBase; this.logBase = logBase;
this.cloudConfig = cloudConfig; this.cloudConfig = cloudConfig;
this.logFilters = logFilters;
} }
/** /**
...@@ -152,25 +151,18 @@ public class LogLocal implements ThreadNext.Next, InitializingBean { ...@@ -152,25 +151,18 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
public boolean isLog(String... keys) { public boolean isLog(String... keys) {
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
list.add(this.cloudConfig.getApplicationName()); list.add(this.cloudConfig.getApplicationName());
for (String item : keys) { list.addAll(Arrays.asList(keys));
list.add(item); for (LogFilter k : logFilters) {
} if (k.logExpect(list)) {
// 是否排除 return true;
boolean notFilter = false;
// 是否过滤
boolean filter = false;
for (String item : list) {
if (item == null) {
continue;
} }
String lower = item.toLowerCase();
notFilter = notFilter || lower.matches(this.cloudConfig.getLogNotFilter());
filter = filter || lower.matches(this.cloudConfig.getLogFilter());
} }
if (notFilter) { for (LogFilter k : logFilters) {
if (k.logFilter(list)) {
return false; return false;
} }
return filter; }
return true;
} }
/** /**
......
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