1 parent
0dc459d50a
commit
ea2808f72b
7 files changed
+198
-11
No files matched your search
@@ -0,0 +1,34 @@
|
||||
package runtimelog
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var legacyStartupLine = regexp.MustCompile(`^(\[[^\]\r\n]+\]\s+\[info\]\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\](?:\[[^\]\r\n]*\])?\[([^\]\r\n]+):\d+\])([^\r\n]*)$`)
|
||||
|
||||
// presentLine 只精简旧版主程序的启动横幅,不修改磁盘原文或隐藏其他来源和级别的记录。
|
||||
func presentLine(line string) (string, bool) {
|
||||
parts := legacyStartupLine.FindStringSubmatch(line)
|
||||
if parts == nil {
|
||||
return line, true
|
||||
}
|
||||
source := strings.ReplaceAll(parts[2], `\`, "/")
|
||||
if source != "internal/app/app.go" && !strings.HasSuffix(source, "/internal/app/app.go") {
|
||||
return line, true
|
||||
}
|
||||
message := strings.TrimSpace(parts[3])
|
||||
if len(message) >= 3 && strings.Trim(message, "*") == "" {
|
||||
return "", false
|
||||
}
|
||||
if !strings.HasPrefix(message, "***\t") && !strings.HasPrefix(message, "*** ") {
|
||||
return line, true
|
||||
}
|
||||
message = strings.TrimSpace(message[3:])
|
||||
for _, prefix := range []string{"Server Version:", "Git Commit Hash:", "Build Date:", "Build GoLang Version:"} {
|
||||
if strings.HasPrefix(message, prefix) {
|
||||
return "", false
|
||||
}
|
||||
}
|
||||
return line, true
|
||||
}
|
||||
@@ -72,16 +72,21 @@ func (w *Writer) Read(ctx context.Context, name string, offset, limit int) (Page
|
||||
if at.Before(cutoff) {
|
||||
return nil
|
||||
}
|
||||
// 先过滤再分页,偏移、统计和下一页判断均按实际可见记录计算。
|
||||
visible, keep := presentLine(string(line))
|
||||
if !keep {
|
||||
return nil
|
||||
}
|
||||
position++
|
||||
if position <= offset {
|
||||
return nil
|
||||
}
|
||||
if len(page.Lines) >= limit || bytes+len(line) > maxResponseBytes {
|
||||
if len(page.Lines) >= limit || bytes+len(visible) > maxResponseBytes {
|
||||
page.HasMore = true
|
||||
return finished
|
||||
}
|
||||
page.Lines = append(page.Lines, string(line))
|
||||
bytes += len(line)
|
||||
page.Lines = append(page.Lines, visible)
|
||||
bytes += len(visible)
|
||||
return nil
|
||||
})
|
||||
if errors.Is(err, finished) {
|
||||
|
||||
Reference in new issue
Block a user