允许用户自定义打印的拓展字段

This commit is contained in:
Yun
2025-06-10 15:41:44 +08:00
parent 3ca01077b6
commit 7dc8dbb539
3 changed files with 28 additions and 2 deletions
+12
View File
@@ -22,6 +22,7 @@ type loggerOption struct {
sizeSplit int // 根据文件大小切割
timeZone *time.Location // 时区
escapeHTML bool
expandData map[string]string // 扩展字段
}
type writeType uint8
@@ -46,6 +47,7 @@ func defaultOptions() loggerOption {
fileSplit: FileSplitTimeE,
timeZone: time.Local,
escapeHTML: true,
expandData: make(map[string]string),
}
}
@@ -58,6 +60,16 @@ func SetTraceField(traceField string) Option {
}
}
// 附加字段
func SetExpandData(key string, value string) Option {
return func(o *loggerOption) {
if o.expandData == nil {
o.expandData = make(map[string]string)
}
o.expandData[key] = value
}
}
// 是否异步写入
func SetWriteAsync() Option {
return func(o *loggerOption) {