-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogContext.java
executable file
·83 lines (70 loc) · 1.86 KB
/
LogContext.java
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
74
75
76
77
78
79
80
81
82
83
package com.lxy.log;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Wu Jie
*
*/
public class LogContext {
private static ThreadLocal<LogContext> currentContext = new ThreadLocal<LogContext>();
public static LogContext getCurrentContext(){
if( currentContext.get()==null ) {
currentContext.set( new LogContext() );
}
return currentContext.get();
}
public static boolean isExistCurrentContext(){
return currentContext.get()!=null;
}
public static void removeCurrrentContext(){
currentContext.remove();
}
/**
* create a new BusinessLog object and add it to current context
* @return created BusinessLog object
*/
public static BusinessLog addLogToCurrrentContext(){
BusinessLog log = new BusinessLog();
getCurrentContext().addLog(log);
return log;
}
private LogContext(){}
private List<BusinessLog> logs = new ArrayList<BusinessLog>();
public void addLog(BusinessLog log){
logs.add( log );
}
public List<BusinessLog> getLogs(){
return logs;
}
public static class BusinessLog {
private Long entityId;
private String entityType;
private String logInfo;
private Object operateEntity;
public Long getEntityId() {
return entityId;
}
public void setEntityId(Long entityId) {
this.entityId = entityId;
}
public String getEntityType() {
return entityType;
}
public void setEntityType(String entityType) {
this.entityType = entityType;
}
public String getLogInfo() {
return logInfo;
}
public void setLogInfo(String logInfo) {
this.logInfo = logInfo;
}
public Object getOperateEntity() {
return operateEntity;
}
public void setOperateEntity(Object operateEntity) {
this.operateEntity = operateEntity;
}
}
}