过滤无价值日志并实现最近24小时倒序分页查询
Security Checks / security (push) Waiting to run

This commit is contained in:
xuans committed 2026-09-09 01:06:45 +08:00
1 parent 161bc3a345
commit bb4ac4d5f5
20 files changed
+765 -132

No files matched your search

+19
View File
@@ -156,6 +156,25 @@ func (l *logFormatter) Format(entry *log.Entry) ([]byte, error) {
}
b.WriteString(fmt.Sprintf("[%s:%d]", entry.Caller.File, entry.Caller.Line))
b.WriteString(entry.Message)
// 错误字段也是有效内容,不能在消息为空时被格式器丢弃。
if len(entry.Data) > 0 {
fields := make(map[string]any, len(entry.Data))
for key, value := range entry.Data {
if cause, ok := value.(error); ok {
fields[key] = cause.Error()
} else if _, err := json.Marshal(value); err != nil {
fields[key] = fmt.Sprintf("无法序列化的字段(%T)", value)
} else {
fields[key] = value
}
}
payload, err := json.Marshal(fields)
if err != nil {
return nil, err
}
b.WriteByte(' ')
b.Write(payload)
}
b.WriteString("\n")
return b.Bytes(), nil