Commit e3517dc3 authored by yanzg's avatar yanzg

不记录系统日志

parent 36056d40
......@@ -22,16 +22,24 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
* 缓存队列
*/
protected volatile Map<String, Timeout<LogVo>> cache = new Hashtable<>();
/**
* 日志基础
*/
@Autowired
private LogBase logBase;
@Value("${spring.application.name}")
protected String applicationName;
/**
* 1个请求最长时间
* 1个请求最长时间(毫秒)
*/
@Value("${yzg.log.time.max:300000}")
private int logTimeMax;
/**
* 1个请求间隔记录时间(毫秒)
*/
@Value("${yzg.timeout:300000}")
private int timeout;
@Value("${yzg.log.time.split:300000}")
private int logTimeSplit;
@Value("${yzg.log.notFilter:^.*login.*$}")
private String notFilter;
......@@ -45,12 +53,6 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
public static final String MAX_TIME = "MAX_TIME";
public static final String MAX_TIME_NAME = "执行超时";
/**
* 日志基础
*/
@Autowired
private LogBase logBase;
/**
* Invoked by a BeanFactory after it has set all bean properties supplied
* (and satisfied BeanFactoryAware and ApplicationContextAware).
......@@ -99,19 +101,8 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
* @return
*/
public void result(LogVo log, String status, String result) {
this.result(log, StringHelper.EMPTY, status, result);
}
/**
* 写入状态
*
* @param status
* @param result
* @return
*/
public void result(LogVo log, String name, String status, String result) {
// 日志请求不记录,防止死循环递归
boolean isLog = isLog(name, log.getActionSubKey());
boolean isLog = isLog(log.getActionKey(), log.getActionSubKey());
if (isLog) {
this.remove(log);
} else {
......@@ -200,7 +191,7 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
keys.addAll(cache.keySet());
for (String key : keys) {
Timeout<LogVo> timeout = cache.get(key);
if (timeout == null || !timeout.isMaxTime(this.timeout)) {
if (timeout == null || !timeout.isMaxTime(this.logTimeMax, this.logTimeSplit)) {
continue;
}
writeTimeout(timeout);
......
......@@ -13,6 +13,11 @@ public class Timeout<T extends Object> {
*/
private long start;
/**
* 上次通知时间
*/
private long prev;
/**
* 结束时间
*/
......@@ -25,6 +30,7 @@ public class Timeout<T extends Object> {
*/
public Timeout(T data) {
this.start = System.currentTimeMillis();
this.prev = start;
this.data = data;
}
......@@ -37,6 +43,15 @@ public class Timeout<T extends Object> {
return start;
}
/**
* 上次判断时间
*
* @return
*/
public long getPrev() {
return prev;
}
/**
* 数据
*
......@@ -52,8 +67,17 @@ public class Timeout<T extends Object> {
* @param maxTime 最大时间
* @return
*/
public boolean isMaxTime(long maxTime) {
long time = System.currentTimeMillis() - start;
return maxTime < time;
public boolean isMaxTime(long maxTime, long prevMaxTime) {
long now = System.currentTimeMillis();
long time = now - start;
long prevTime = now - prev;
boolean ret = maxTime < time;
if (ret) {
if (prev != start && prevMaxTime > prevTime) {
return false;
}
prev = now;
}
return ret;
}
}
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