You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
522 B
27 lines
522 B
package DouTokContext
|
|
|
|
import (
|
|
"go.uber.org/zap"
|
|
"go.uber.org/zap/zapcore"
|
|
)
|
|
|
|
func Nest(key string, fields ...zapcore.Field) zapcore.Field {
|
|
return zapcore.Field{
|
|
Key: key,
|
|
Type: zapcore.ObjectMarshalerType,
|
|
Interface: Fields(fields),
|
|
}
|
|
}
|
|
|
|
type Fields []zap.Field
|
|
|
|
func (fs Fields) MarshallLogObject(enc zapcore.ObjectEncoder) error {
|
|
addFields(enc, []zap.Field(fs))
|
|
return nil
|
|
}
|
|
|
|
func addFields(enc zapcore.ObjectEncoder, fields []zap.Field) {
|
|
for i := range fields {
|
|
fields[i].AddTo(enc)
|
|
}
|
|
}
|
|
|