1Panel
1Panel copied to clipboard
[FEATURE]给日志加上搜索功能
1Panel 版本
v1.9.5
请描述您的需求或者改进建议
目前日志缺少搜索功能 想要快速找到关键内容比较困难
请描述你建议的实现方案
目前已有一点粗略思路 前端部分 添加搜索框 获取日志时提交搜索字段 后段 将获取到的日志 通过 bytes.Index函数获取到位置 然后查找前一个换行符 和 后一个换行符 以实现获取完整的一行数据 以下为demo代码
` // findAllSubstrings returns all contents between newlines for all occurrences of the substring. func findAllSubstrings(data []byte, substring []byte) ([]string, error) { var contents []string startIndex := 0
for {
// Find the substring in data starting at startIndex.
substringIndex := bytes.Index(data[startIndex:], substring)
if substringIndex == -1 {
break
}
substringIndex += startIndex
// Find the newline before the substring.
start := bytes.LastIndexByte(data[:substringIndex], '\n')
if start == -1 {
start = 0
} else {
start += 1 // To exclude the newline itself.
}
// Find the newline after the substring.
end := bytes.IndexByte(data[substringIndex:], '\n')
if end != -1 {
end += substringIndex
} else {
end = len(data)
}
// Append the content to the result slice.
contents = append(contents, string(data[start:end]))
// Move the startIndex to the end of the found content (end + newline's size)
startIndex = end + 1
}
if len(contents) == 0 {
return nil, fmt.Errorf("no matching content found")
}
return contents, nil
} `
附加信息
No response
感谢反馈,我们会在后续版本支持上述需求。
感谢反馈,我们会在后续版本支持上述需求。
还有个问题 条数里不该出现全部选项 我这运行两天的日志量选择全部的话就会无反应了 建议改为自定义数量 但是必须得填一个大于0的数值