MCPcopy
hub / github.com/rs/zerolog / AnErr

Method AnErr

context.go:183–199  ·  view source on GitHub ↗

AnErr adds the field key with serialized err to the logger context. If err is nil, no field is added.

(key string, err error)

Source from the content-addressed store, hash-verified

181// AnErr adds the field key with serialized err to the logger context.
182// If err is nil, no field is added.
183func (c Context) AnErr(key string, err error) Context {
184 switch m := ErrorMarshalFunc(err).(type) {
185 case nil:
186 return c
187 case LogObjectMarshaler:
188 return c.Object(key, m)
189 case error:
190 if isNilValue(m) {
191 return c
192 }
193 return c.Str(key, m.Error())
194 case string:
195 return c.Str(key, m)
196 default:
197 return c.Interface(key, m)
198 }
199}
200
201// Errs adds the field key with errs as an array of serialized errors to the
202// logger context.

Callers 1

ErrMethod · 0.95

Calls 5

ObjectMethod · 0.95
StrMethod · 0.95
InterfaceMethod · 0.95
isNilValueFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected