MCPcopy
hub / github.com/uber-go/zap / AddTo

Method AddTo

zapcore/field.go:114–186  ·  zapcore/field.go::Field.AddTo

AddTo exports a field through the ObjectEncoder interface. It's primarily useful to library authors, and shouldn't be necessary in most applications.

(enc ObjectEncoder)

Source from the content-addressed store, hash-verified

112// AddTo exports a field through the ObjectEncoder interface. It's primarily
113// useful to library authors, and shouldn't be necessary in most applications.
114func (f Field) AddTo(enc ObjectEncoder) {
115 var err error
116
117 switch f.Type {
118 case ArrayMarshalerType:
119 err = enc.AddArray(f.Key, f.Interface.(ArrayMarshaler))
120 case ObjectMarshalerType:
121 err = enc.AddObject(f.Key, f.Interface.(ObjectMarshaler))
122 case InlineMarshalerType:
123 err = f.Interface.(ObjectMarshaler).MarshalLogObject(enc)
124 case BinaryType:
125 enc.AddBinary(f.Key, f.Interface.([]byte))
126 case BoolType:
127 enc.AddBool(f.Key, f.Integer == 1)
128 case ByteStringType:
129 enc.AddByteString(f.Key, f.Interface.([]byte))
130 case Complex128Type:
131 enc.AddComplex128(f.Key, f.Interface.(complex128))
132 case Complex64Type:
133 enc.AddComplex64(f.Key, f.Interface.(complex64))
134 case DurationType:
135 enc.AddDuration(f.Key, time.Duration(f.Integer))
136 case Float64Type:
137 enc.AddFloat64(f.Key, math.Float64frombits(uint64(f.Integer)))
138 case Float32Type:
139 enc.AddFloat32(f.Key, math.Float32frombits(uint32(f.Integer)))
140 case Int64Type:
141 enc.AddInt64(f.Key, f.Integer)
142 case Int32Type:
143 enc.AddInt32(f.Key, int32(f.Integer))
144 case Int16Type:
145 enc.AddInt16(f.Key, int16(f.Integer))
146 case Int8Type:
147 enc.AddInt8(f.Key, int8(f.Integer))
148 case StringType:
149 enc.AddString(f.Key, f.String)
150 case TimeType:
151 if f.Interface != nil {
152 enc.AddTime(f.Key, time.Unix(0, f.Integer).In(f.Interface.(*time.Location)))
153 } else {
154 // Fall back to UTC if location is nil.
155 enc.AddTime(f.Key, time.Unix(0, f.Integer))
156 }
157 case TimeFullType:
158 enc.AddTime(f.Key, f.Interface.(time.Time))
159 case Uint64Type:
160 enc.AddUint64(f.Key, uint64(f.Integer))
161 case Uint32Type:
162 enc.AddUint32(f.Key, uint32(f.Integer))
163 case Uint16Type:
164 enc.AddUint16(f.Key, uint16(f.Integer))
165 case Uint8Type:
166 enc.AddUint8(f.Key, uint8(f.Integer))
167 case UintptrType:
168 enc.AddUintptr(f.Key, uintptr(f.Integer))
169 case ReflectType:
170 err = enc.AddReflected(f.Key, f.Interface)
171 case NamespaceType:

Callers 15

TestUnknownFieldTypeFunction · 0.95
TestFieldAddingErrorFunction · 0.95
TestFieldsFunction · 0.95
TestInlineMarshalerFunction · 0.95
TestErrorEncodingFunction · 0.95
TestRichErrorSupportFunction · 0.95
assertCanBeReusedFunction · 0.80
TestDictFunction · 0.80
TestDictObjectFunction · 0.80
MarshalLogObjectMethod · 0.80

Calls 15

encodeStringerFunction · 0.85
encodeErrorFunction · 0.85
AddArrayMethod · 0.65
AddObjectMethod · 0.65
MarshalLogObjectMethod · 0.65
AddBinaryMethod · 0.65
AddBoolMethod · 0.65
AddByteStringMethod · 0.65
AddComplex128Method · 0.65
AddComplex64Method · 0.65
AddDurationMethod · 0.65
AddFloat64Method · 0.65

Tested by 15

TestUnknownFieldTypeFunction · 0.76
TestFieldAddingErrorFunction · 0.76
TestFieldsFunction · 0.76
TestInlineMarshalerFunction · 0.76
TestErrorEncodingFunction · 0.76
TestRichErrorSupportFunction · 0.76
assertCanBeReusedFunction · 0.64
TestDictFunction · 0.64
TestDictObjectFunction · 0.64