1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.yanzuoguang.cloud.aop;
import com.yanzuoguang.cloud.CloudConfig;
import com.yanzuoguang.cloud.aop.log.LogLocal;
import com.yanzuoguang.log.LogCountTime;
import com.yanzuoguang.util.log.Log;
import com.yanzuoguang.util.vo.LogVo;
import org.springframework.stereotype.Component;
/**
* 写入日志
*
* @author 颜佐光
*/
@Component
public class AspectLogStart {
private final CloudConfig cloudConfig;
private final LogLocal logLocal;
private final AspectLogBody aspectLogBody;
private final LogCountTime logCountTime;
public AspectLogStart(CloudConfig cloudConfig, LogLocal logLocal, AspectLogBody aspectLogBody, LogCountTime logCountTime) {
this.cloudConfig = cloudConfig;
this.logLocal = logLocal;
this.aspectLogBody = aspectLogBody;
this.logCountTime = logCountTime;
}
/**
* 记录请求日志
*
* @param tag
* @param url
* @param requestBody
* @param log
* @param logFlag
* @return
*/
// @Async
public void requestLog(Class<?> cls, String tag, String url, Object requestBody, LogVo log, boolean logFlag) {
try {
String fullUrl = String.format("%s:%s", tag, url);
logCountTime.start(fullUrl);
String body = aspectLogBody.getBodyString(requestBody);
if (logFlag) {
this.logLocal.startLog(log, tag, String.format("%s:%s", this.cloudConfig.getApplicationName(), url), body);
}
boolean isLog = logFlag && this.cloudConfig.isLogCommon();
if (isLog) {
Log.info(cls, " %s [ %s ] request: %s", tag, url, body);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* 获取是否清空日志的标签
*
* @return 返回日志是否清空
*/
protected boolean requestLogInit() {
boolean clear = Log.threadCurrent() == null;
if (clear) {
Log.threadBegin();
}
return clear;
}
}