Files
weichenandCursor bed0dbf076
ci / vet-and-test (push) Successful in 4s
ci / docker-checkout-hostgateway (push) Successful in 2s
Add a structured logger and collector so runs can be traced across processes.
Sync and async sinks, redaction, and a queryable HTTP service keep concurrent logs tied to a trace id.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-29 13:51:16 +00:00

32 lines
949 B
Go

package logsys
import "time"
// Entry 是一条已结构化的日志。JSON 字段名跨进程稳定。
type Entry struct {
Time time.Time `json:"ts"`
Level string `json:"level"`
Service string `json:"service,omitempty"`
Module string `json:"module,omitempty"`
Message string `json:"msg"`
TraceID string `json:"trace_id,omitempty"`
Error string `json:"error,omitempty"`
Code string `json:"code,omitempty"`
Fields map[string]any `json:"fields,omitempty"`
}
// Sink 是日志出口。实现必须允许多个 goroutine 同时 Write。
// Sync 把缓冲刷出;Close 之后不得再 Write。
type Sink interface {
Write(e Entry) error
Sync() error
Close() error
}
// codedError 是错误码模块的鸭子接口。实现这两个方法即可被展开,无需互相引用。
type codedError interface {
error
ErrorCode() string
ErrorFields() map[string]any
}