mirror of
https://github.com/gotoeasy/glogcenter.git
synced 2025-09-15 12:58:34 +08:00
日志级别条件支持多选
This commit is contained in:
parent
451f8975b2
commit
c813ddbcb0
@ -56,12 +56,6 @@ func (e *Engine) Search(searchKey string, system string, minDatetime string, max
|
||||
adds = append(adds, system, loglevel)
|
||||
kws := tokenizer.CutForSearchEx(searchKey, adds, nil) // 检索用关键词处理
|
||||
|
||||
if searchKey == "" {
|
||||
cmn.Debug("无条件查询", "currentDocId =", currentDocId)
|
||||
} else {
|
||||
cmn.Debug("查询", searchKey, ",分词后检索", kws, "currentDocId =", currentDocId)
|
||||
}
|
||||
|
||||
// 简单检查,存在无索引数据的关键词时,直接返回
|
||||
for _, word := range kws {
|
||||
idxw := indexword.NewWordIndexStorage(e.storeName)
|
||||
@ -75,8 +69,8 @@ func (e *Engine) Search(searchKey string, system string, minDatetime string, max
|
||||
}
|
||||
|
||||
if len(kws) == 0 {
|
||||
// 无条件浏览模式
|
||||
return search.SearchLogData(e.storeName, currentDocId, forward, minDatetime, maxDatetime)
|
||||
// 无条件浏览模式(可能含多选条件)
|
||||
return search.SearchLogData(e.storeName, loglevels, currentDocId, forward, minDatetime, maxDatetime)
|
||||
}
|
||||
|
||||
// 多关键词查询模式
|
||||
|
||||
@ -79,13 +79,15 @@ func SearchWordIndex(storeName string, kws []string, loglevels []string, current
|
||||
}
|
||||
|
||||
// 无关键词时走全量检索
|
||||
func SearchLogData(storeName string, currentDocId uint32, forward bool, minDatetime string, maxDatetime string) *SearchResult {
|
||||
|
||||
func SearchLogData(storeName string, loglevels []string, currentDocId uint32, forward bool, minDatetime string, maxDatetime string) *SearchResult {
|
||||
allloglevels := cmn.Join(loglevels, ",") // 合并多选的级别条件
|
||||
noLogLevels := cmn.IsBlank(allloglevels) // 无多选条件
|
||||
var rs = new(SearchResult) // 检索结果
|
||||
storeLogData := storage.NewLogDataStorageHandle(storeName) // 数据
|
||||
totalCount := storeLogData.TotalCount() // 总件数
|
||||
rs.Total = cmn.Uint32ToString(totalCount) // 返回的日志总量件数,用10进制字符串形式以避免出现科学计数法
|
||||
rs.Count = cmn.Uint32ToString(totalCount) // 当前条件最多匹配件数
|
||||
rsCnt := 0 // 已查到的件数
|
||||
|
||||
if totalCount == 0 {
|
||||
return rs
|
||||
@ -135,18 +137,19 @@ func SearchLogData(storeName string, currentDocId uint32, forward bool, minDatet
|
||||
max = maxDocumentId // 最大不超出时间范围限制内的最大文档ID
|
||||
}
|
||||
|
||||
if max > uint32(conf.GetPageSize()) {
|
||||
min = max - uint32(conf.GetPageSize()) + 1
|
||||
} else {
|
||||
min = 1
|
||||
}
|
||||
|
||||
if min < minDocumentId {
|
||||
min = minDocumentId // 最小不超出时间范围限制内的最小文档ID
|
||||
}
|
||||
|
||||
for i := max; i >= min; i-- {
|
||||
rs.Data = append(rs.Data, storeLogData.GetLogDataDocument(i).ToLogDataModel()) // 件数等同日志文档ID
|
||||
md := storeLogData.GetLogDataDocument(i).ToLogDataModel()
|
||||
if noLogLevels || cmn.ContainsIngoreCase(allloglevels, md.LogLevel) {
|
||||
rs.Data = append(rs.Data, md)
|
||||
rsCnt++
|
||||
if rsCnt >= conf.GetPageSize() {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if forward {
|
||||
// 后一页
|
||||
@ -162,18 +165,19 @@ func SearchLogData(storeName string, currentDocId uint32, forward bool, minDatet
|
||||
max = maxDocumentId // 最大不超出时间范围限制内的最大文档ID
|
||||
}
|
||||
|
||||
if max > uint32(conf.GetPageSize()) {
|
||||
min = max - uint32(conf.GetPageSize()) + 1
|
||||
} else {
|
||||
min = 1
|
||||
}
|
||||
|
||||
if min < minDocumentId {
|
||||
min = minDocumentId // 最小不超出时间范围限制内的最小文档ID
|
||||
}
|
||||
|
||||
for i := max; i >= min; i-- {
|
||||
rs.Data = append(rs.Data, storeLogData.GetLogDataDocument(i).ToLogDataModel())
|
||||
md := storeLogData.GetLogDataDocument(i).ToLogDataModel()
|
||||
if noLogLevels || cmn.ContainsIngoreCase(allloglevels, md.LogLevel) {
|
||||
rs.Data = append(rs.Data, md)
|
||||
rsCnt++
|
||||
if rsCnt >= conf.GetPageSize() {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -186,17 +190,20 @@ func SearchLogData(storeName string, currentDocId uint32, forward bool, minDatet
|
||||
min = minDocumentId // 最小不超出时间范围限制内的最小文档ID
|
||||
}
|
||||
|
||||
max = min + uint32(conf.GetPageSize()) - 1
|
||||
if max > totalCount {
|
||||
max = totalCount
|
||||
}
|
||||
|
||||
if max > maxDocumentId {
|
||||
max = maxDocumentId // 最大不超出时间范围限制内的最大文档ID
|
||||
}
|
||||
|
||||
for i := max; i >= min; i-- {
|
||||
rs.Data = append(rs.Data, storeLogData.GetLogDataDocument(i).ToLogDataModel())
|
||||
md := storeLogData.GetLogDataDocument(i).ToLogDataModel()
|
||||
if noLogLevels || cmn.ContainsIngoreCase(allloglevels, md.LogLevel) {
|
||||
rs.Data = append(rs.Data, md)
|
||||
rsCnt++
|
||||
if rsCnt >= conf.GetPageSize() {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -206,9 +213,9 @@ func SearchLogData(storeName string, currentDocId uint32, forward bool, minDatet
|
||||
|
||||
// 参数widxs长度要求大于1,currentDocId不传就是查第一页
|
||||
func findSame(currentDocId uint32, loglevels []string, forward bool, minDocumentId uint32, maxDocumentId uint32, storeLogData *storage.LogDataStorageHandle, widxs ...*WidxStorage) *SearchResult {
|
||||
|
||||
allloglevels := cmn.Join(loglevels, ",")
|
||||
var rs = new(SearchResult)
|
||||
allloglevels := cmn.Join(loglevels, ",") // 合并多选的级别条件
|
||||
noLogLevels := cmn.IsBlank(allloglevels) // 无多选条件
|
||||
var rs = new(SearchResult) // 查询结果
|
||||
rs.Total = cmn.Uint32ToString(storeLogData.TotalCount()) // 日志总量件数
|
||||
|
||||
// 选个最短的索引
|
||||
@ -277,20 +284,12 @@ func findSame(currentDocId uint32, loglevels []string, forward bool, minDocument
|
||||
// 找到则加入结果
|
||||
if flg {
|
||||
md := storeLogData.GetLogDataModel(docId)
|
||||
if len(loglevels) > 0 {
|
||||
// 多选条件时做匹配判断
|
||||
if cmn.ContainsIngoreCase(allloglevels, md.LogLevel) {
|
||||
rsCnt++
|
||||
rs.Data = append(rs.Data, md)
|
||||
}
|
||||
} else {
|
||||
// 单选或全选时找到的都是匹配的
|
||||
if noLogLevels || cmn.ContainsIngoreCase(allloglevels, md.LogLevel) {
|
||||
rsCnt++
|
||||
rs.Data = append(rs.Data, md)
|
||||
}
|
||||
|
||||
if rsCnt >= conf.GetPageSize() {
|
||||
break // 最多找一页
|
||||
if rsCnt >= conf.GetPageSize() {
|
||||
break // 最多找一页
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -324,10 +323,13 @@ func findSame(currentDocId uint32, loglevels []string, forward bool, minDocument
|
||||
}
|
||||
// 找到则加入结果
|
||||
if flg {
|
||||
rsCnt++
|
||||
ary = append(ary, storeLogData.GetLogDataModel(docId))
|
||||
if rsCnt >= conf.GetPageSize() {
|
||||
break // 最多找一页
|
||||
md := storeLogData.GetLogDataModel(docId)
|
||||
if noLogLevels || cmn.ContainsIngoreCase(allloglevels, md.LogLevel) {
|
||||
rsCnt++
|
||||
ary = append(ary, md)
|
||||
if rsCnt >= conf.GetPageSize() {
|
||||
break // 最多找一页
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,7 +168,7 @@ func (s *WordIndexStorage) Add(word string, docId uint32) error {
|
||||
cmn.Error("保存关键词反向索引件数失败", err)
|
||||
return err // 忽略事务问题,可下回重建
|
||||
}
|
||||
cmn.Debug("创建日志索引:", docId, ",关键词:", word)
|
||||
// cmn.Debug("创建日志索引:", docId, ",关键词:", word)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -200,7 +200,7 @@ func (s *LogDataStorage) createInvertedIndex() int {
|
||||
idxw := indexword.NewWordIndexStorage(s.StoreName())
|
||||
idxw.Add(word, cmn.StringToUint32(docm.Id, 0)) // 日志ID加入索引
|
||||
}
|
||||
cmn.Debug("创建日志索引:", cmn.StringToUint32(docm.Id, 0))
|
||||
// cmn.Debug("创建日志索引:", cmn.StringToUint32(docm.Id, 0))
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ func fnAmqpJsonLogHandle(jsonLog string, err error) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
cmn.Debug("接收到rabbitmq的日志", jsonLog)
|
||||
// cmn.Debug("接收到rabbitmq的日志", jsonLog)
|
||||
|
||||
md := &logdata.LogDataModel{}
|
||||
if conf.IsAmqpJsonFormat() {
|
||||
|
||||
@ -31,7 +31,7 @@ func LogSearchController(req *gweb.HttpRequest) *gweb.HttpResult {
|
||||
if !cmn.IsBlank(system) {
|
||||
system = "~" + cmn.Trim(system)
|
||||
}
|
||||
if !cmn.IsBlank(loglevel) && len(loglevels) == 0 {
|
||||
if !cmn.IsBlank(loglevel) && !cmn.Contains(loglevel, ",") {
|
||||
loglevel = "!" + cmn.Trim(loglevel) // 单个条件时作为索引条件
|
||||
} else {
|
||||
loglevel = "" // 多选条件时不使用,改用loglevels
|
||||
|
||||
@ -205,7 +205,7 @@ function search() {
|
||||
data.searchKey = formData.value.searchKeys;
|
||||
data.storeName = formData.value.storage;
|
||||
data.system = formData.value.system;
|
||||
data.loglevel = formData.value.loglevel.join(',');
|
||||
data.loglevel = (formData.value.loglevel || []).join(',');
|
||||
data.datetimeFrom = (formData.value.datetime || ['', ''])[0];
|
||||
data.datetimeTo = (formData.value.datetime || ['', ''])[1];
|
||||
|
||||
@ -251,7 +251,7 @@ function searchMore() {
|
||||
data.searchKey = formData.value.searchKeys;
|
||||
data.storeName = formData.value.storage;
|
||||
data.system = formData.value.system;
|
||||
data.loglevel = formData.value.loglevel.join(',');
|
||||
data.loglevel = (formData.value.loglevel || []).join(',');
|
||||
data.datetimeFrom = (formData.value.datetime || ['', ''])[0];
|
||||
data.datetimeTo = (formData.value.datetime || ['', ''])[1];
|
||||
data.forward = true
|
||||
|
||||
Loading…
Reference in New Issue
Block a user