feat(logger): WithSource/Scoped 日志来源标注;AGENTS 追加日志标来源+客户端API契约红线
This commit is contained in:
1 parent
be67d74822
commit
10c0069fa7
3 files changed
+48
No files matched your search
@@ -68,3 +68,24 @@ func ParseLevel(s string) slog.Level {
|
||||
return slog.LevelInfo
|
||||
}
|
||||
}
|
||||
|
||||
// WithSource returns a child logger that tags every emitted record with a
|
||||
// source so issues can be traced back to the owning module/sub-feature. source
|
||||
// is conventionally "module/subfeature", e.g. "runtime/loop" or
|
||||
// "channel/adapter". Every module that logs should call this once on its base
|
||||
// logger so all records carry provenance.
|
||||
func WithSource(l *slog.Logger, source string) *slog.Logger {
|
||||
if l == nil {
|
||||
return nil
|
||||
}
|
||||
return l.With(slog.String("source", source))
|
||||
}
|
||||
|
||||
// Scoped returns a child logger tagged with module and subfeature, for finer
|
||||
// provenance when a module contains several subsystems.
|
||||
func Scoped(l *slog.Logger, module, subfeature string) *slog.Logger {
|
||||
if l == nil {
|
||||
return nil
|
||||
}
|
||||
return l.With(slog.String("module", module), slog.String("sub", subfeature))
|
||||
}
|
||||
Reference in new issue
Block a user