mirror of
https://github.com/gotoeasy/glogcenter.git
synced 2025-09-15 12:58:34 +08:00
0.10.1 clientip/traceid/loglevel
This commit is contained in:
parent
1aa5026d92
commit
96714d705a
@ -95,8 +95,8 @@ public class GlcAmqpAppender extends AppenderBase<ILoggingEvent> {
|
||||
initConnectionChannel();
|
||||
}
|
||||
|
||||
String traceid = MdcUtil.getTraceId();
|
||||
String clientip = MdcUtil.getClientIp();
|
||||
String traceid = event.getMDCPropertyMap().get(MdcUtil.TRACE_ID);
|
||||
String clientip = event.getMDCPropertyMap().get(MdcUtil.CLIENT_IP);
|
||||
|
||||
String body = "{\"text\":" + Util.encodeStr(text.trim());
|
||||
body += ",\"date\":\"" + Util.getDateString() + "\"";
|
||||
@ -104,10 +104,10 @@ public class GlcAmqpAppender extends AppenderBase<ILoggingEvent> {
|
||||
body += ",\"servername\":" + Util.encodeStr(Util.getServerName());
|
||||
body += ",\"serverip\":" + Util.encodeStr(Util.getServerIp());
|
||||
body += ",\"loglevel\":\"" + event.getLevel().toString() + "\"";
|
||||
if (!"".equals(traceid)) {
|
||||
if (traceid != null && !"".equals(traceid)) {
|
||||
body += ",\"traceid\":" + Util.encodeStr(traceid);
|
||||
}
|
||||
if (!"".equals(clientip)) {
|
||||
if (clientip != null && !"".equals(clientip)) {
|
||||
body += ",\"clientip\":" + Util.encodeStr(clientip);
|
||||
}
|
||||
body += "}";
|
||||
|
||||
@ -65,8 +65,8 @@ public class GlcHttpJsonAppender extends AppenderBase<ILoggingEvent> {
|
||||
DataOutputStream dos = null;
|
||||
String body = null;
|
||||
try {
|
||||
String traceid = MdcUtil.getTraceId();
|
||||
String clientip = MdcUtil.getClientIp();
|
||||
String traceid = event.getMDCPropertyMap().get(MdcUtil.TRACE_ID);
|
||||
String clientip = event.getMDCPropertyMap().get(MdcUtil.CLIENT_IP);
|
||||
|
||||
body = "{\"text\":" + Util.encodeStr(text.trim());
|
||||
body += ",\"date\":\"" + Util.getDateString() + "\"";
|
||||
@ -74,10 +74,10 @@ public class GlcHttpJsonAppender extends AppenderBase<ILoggingEvent> {
|
||||
body += ",\"servername\":" + Util.encodeStr(Util.getServerName());
|
||||
body += ",\"serverip\":" + Util.encodeStr(Util.getServerIp());
|
||||
body += ",\"loglevel\":\"" + event.getLevel().toString() + "\"";
|
||||
if (!"".equals(traceid)) {
|
||||
if (traceid != null && !"".equals(traceid)) {
|
||||
body += ",\"traceid\":" + Util.encodeStr(traceid);
|
||||
}
|
||||
if (!"".equals(clientip)) {
|
||||
if (clientip != null && !"".equals(clientip)) {
|
||||
body += ",\"clientip\":" + Util.encodeStr(clientip);
|
||||
}
|
||||
body += "}";
|
||||
|
||||
@ -9,16 +9,6 @@ public class MdcUtil {
|
||||
public static final String TRACE_ID = "traceid";
|
||||
public static final String CLIENT_IP = "clientip";
|
||||
|
||||
public static String getClientIp() {
|
||||
String str = MDC.get(CLIENT_IP);
|
||||
return str == null ? "" : str;
|
||||
}
|
||||
|
||||
public static String getTraceId() {
|
||||
String str = MDC.get(TRACE_ID);
|
||||
return str == null ? "" : str;
|
||||
}
|
||||
|
||||
public static void setClientIp(String clientip) {
|
||||
MDC.put(CLIENT_IP, clientip);
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ func (e *Engine) AddLogDataModel(data *logdata.LogDataModel) {
|
||||
e.logStorage.AddLogDataModel(data)
|
||||
}
|
||||
|
||||
func (e *Engine) Search(searchKey string, system string, minDatetime string, maxDatetime string, loglevel string, traceid string,
|
||||
func (e *Engine) Search(searchKey string, system string, minDatetime string, maxDatetime string, loglevel string,
|
||||
pageSize int, currentDocId uint32, forward bool) *search.SearchResult {
|
||||
|
||||
// 检查修正pageSize
|
||||
@ -61,7 +61,7 @@ func (e *Engine) Search(searchKey string, system string, minDatetime string, max
|
||||
|
||||
// 分词后检索
|
||||
var adds []string
|
||||
adds = append(adds, system, loglevel, traceid)
|
||||
adds = append(adds, system, loglevel)
|
||||
kws := tokenizer.CutForSearchEx(searchKey, adds, nil) // 检索用关键词处理
|
||||
|
||||
if searchKey == "" {
|
||||
|
||||
@ -46,7 +46,7 @@ func Test_all(t *testing.T) {
|
||||
// }
|
||||
// time.Sleep(time.Duration(5) * time.Second)
|
||||
|
||||
rs := engine.Search(` them java `, "", "", "", "", "", 5, 0, true)
|
||||
rs := engine.Search(` them java `, "", "", "", "", 5, 0, true)
|
||||
cmn.Println("共查到", rs.Total, "件")
|
||||
for _, v := range rs.Data {
|
||||
cmn.Println(v.Id, v.Text)
|
||||
|
||||
@ -20,7 +20,7 @@ type LogDataModel struct {
|
||||
System string `json:"system,omitempty"` // 系统名
|
||||
ServerName string `json:"servername,omitempty"` // 服务器名
|
||||
ServerIp string `json:"serverip,omitempty"` // 服务器IP
|
||||
ClientIp string `json:"client,omitempty"` // 客户端IP
|
||||
ClientIp string `json:"clientip,omitempty"` // 客户端IP
|
||||
TraceId string `json:"traceid,omitempty"` // 跟踪ID
|
||||
LogType string `json:"logtype,omitempty"` // 日志类型(1:登录日志、2:操作日志)
|
||||
LogLevel string `json:"loglevel,omitempty"` // 日志级别(debug、info、error等)
|
||||
|
||||
@ -189,32 +189,8 @@ func (s *LogDataStorage) createInvertedIndex() int {
|
||||
if docm.System != "" {
|
||||
adds = append(adds, "~"+docm.System)
|
||||
}
|
||||
if docm.ServerName != "" {
|
||||
adds = append(adds, "!"+docm.ServerName)
|
||||
}
|
||||
if docm.ServerIp != "" {
|
||||
adds = append(adds, "@"+docm.ServerIp)
|
||||
}
|
||||
if docm.ClientIp != "" {
|
||||
adds = append(adds, "#"+docm.ClientIp)
|
||||
}
|
||||
if docm.TraceId != "" {
|
||||
adds = append(adds, "$"+docm.TraceId)
|
||||
}
|
||||
if docm.LogType != "" {
|
||||
adds = append(adds, "%"+docm.LogType)
|
||||
}
|
||||
if docm.User != "" {
|
||||
adds = append(adds, "^"+docm.User)
|
||||
}
|
||||
if docm.Module != "" {
|
||||
adds = append(adds, "&"+docm.Module)
|
||||
}
|
||||
if docm.Operation != "" {
|
||||
adds = append(adds, "*"+docm.Operation)
|
||||
}
|
||||
if docm.LogLevel != "" {
|
||||
adds = append(adds, "-"+docm.LogLevel)
|
||||
adds = append(adds, "!"+docm.LogLevel)
|
||||
}
|
||||
kws := tokenizer.CutForSearchEx(docm.Text+" "+docm.System+" "+docm.ServerName+" "+docm.ServerIp+
|
||||
" "+docm.ClientIp+" "+docm.TraceId+" "+docm.LogLevel+" "+docm.User+" "+docm.Module+" "+docm.Operation, adds, docm.Sensitives) // 两数组参数的元素可以重复或空白,会被判断整理
|
||||
|
||||
@ -25,19 +25,15 @@ func LogSearchController(req *gweb.HttpRequest) *gweb.HttpResult {
|
||||
datetimeTo := req.GetFormParameter("datetimeTo")
|
||||
system := req.GetFormParameter("system")
|
||||
loglevel := req.GetFormParameter("loglevel")
|
||||
traceid := req.GetFormParameter("traceid")
|
||||
|
||||
if !cmn.IsBlank(system) {
|
||||
system = "~" + cmn.Trim(system)
|
||||
}
|
||||
if !cmn.IsBlank(traceid) {
|
||||
traceid = "$" + cmn.Trim(traceid)
|
||||
}
|
||||
if !cmn.IsBlank(loglevel) {
|
||||
loglevel = "-" + cmn.Trim(loglevel)
|
||||
loglevel = "!" + cmn.Trim(loglevel)
|
||||
}
|
||||
|
||||
eng := ldb.NewEngine(storeName)
|
||||
rs := eng.Search(searchKey, system, datetimeFrom, datetimeTo, loglevel, traceid, pageSize, currentId, forward)
|
||||
rs := eng.Search(searchKey, system, datetimeFrom, datetimeTo, loglevel, pageSize, currentId, forward)
|
||||
return gweb.Result(rs)
|
||||
}
|
||||
|
||||
@ -109,6 +109,7 @@
|
||||
<el-dropdown-item @click="switchVisible('system')">{{systemVisible?'隐藏':'显示'}}系统名</el-dropdown-item>
|
||||
<el-dropdown-item @click="switchVisible('servername')">{{serverNameVisible?'隐藏':'显示'}}主机名</el-dropdown-item>
|
||||
<el-dropdown-item @click="switchVisible('serverip')">{{serverIpVisible?'隐藏':'显示'}}主机IP</el-dropdown-item>
|
||||
<el-dropdown-item @click="switchVisible('clientip')">{{clientIpVisible?'隐藏':'显示'}}客户端IP</el-dropdown-item>
|
||||
<el-dropdown-item @click="switchVisible('date')">{{dateVisible?'隐藏':'显示'}}日期时间</el-dropdown-item>
|
||||
<el-dropdown-item @click="switchVisible('loglevel')">{{logLevelVisible?'隐藏':'显示'}}Level</el-dropdown-item>
|
||||
<el-dropdown-item @click="switchVisible('traceid')">{{traceIdVisible?'隐藏':'显示'}}TraceID</el-dropdown-item>
|
||||
@ -137,6 +138,7 @@
|
||||
<el-table-column v-if="systemVisible" prop="system" label="系统名" width="120" :show-overflow-tooltip="true"/>
|
||||
<el-table-column v-if="serverNameVisible" prop="servername" label="主机名" width="180" :show-overflow-tooltip="true"/>
|
||||
<el-table-column v-if="serverIpVisible" prop="serverip" label="主机IP" width="130" :show-overflow-tooltip="true"/>
|
||||
<el-table-column v-if="clientIpVisible" prop="clientip" label="客户端IP" width="130" :show-overflow-tooltip="true"/>
|
||||
<el-table-column v-if="dateVisible" prop="date" label="日期时间" width="208" :show-overflow-tooltip="true"/>
|
||||
<el-table-column v-if="logLevelVisible" prop="loglevel" label="Level" width="75" :show-overflow-tooltip="true"/>
|
||||
<el-table-column v-if="traceIdVisible" prop="traceid" label="TraceId" width="300" :show-overflow-tooltip="true"/>
|
||||
@ -190,7 +192,8 @@ export default {
|
||||
systemVisible: true,
|
||||
serverNameVisible: false,
|
||||
serverIpVisible: false,
|
||||
logLevelVisible: true,
|
||||
clientIpVisible: false,
|
||||
logLevelVisible: false,
|
||||
traceIdVisible: false,
|
||||
dateVisible: true,
|
||||
info: '',
|
||||
@ -329,6 +332,7 @@ export default {
|
||||
name == 'system' && (this.systemVisible = !this.systemVisible);
|
||||
name == 'servername' && (this.serverNameVisible = !this.serverNameVisible);
|
||||
name == 'serverip' && (this.serverIpVisible = !this.serverIpVisible);
|
||||
name == 'clientip' && (this.clientIpVisible = !this.clientIpVisible);
|
||||
name == 'loglevel' && (this.logLevelVisible = !this.logLevelVisible);
|
||||
name == 'traceid' && (this.traceIdVisible = !this.traceIdVisible);
|
||||
name == 'date' && (this.dateVisible = !this.dateVisible);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user