Commit e3517dc3 authored by yanzg's avatar yanzg

不记录系统日志

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