允许用户自定义打印的拓展字段
This commit is contained in:
+12
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user