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

Method AnErr

event.go:422–441  ·  view source on GitHub ↗

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

(key string, err error)

Source from the content-addressed store, hash-verified

420// AnErr adds the field key with serialized err to the *Event context.
421// If err is nil, no field is added.
422func (e *Event) AnErr(key string, err error) *Event {
423 if e == nil {
424 return e
425 }
426 switch m := ErrorMarshalFunc(err).(type) {
427 case nil:
428 return e
429 case LogObjectMarshaler:
430 return e.Object(key, m)
431 case error:
432 if isNilValue(m) {
433 return e
434 }
435 return e.Str(key, m.Error())
436 case string:
437 return e.Str(key, m)
438 default:
439 return e.Interface(key, m)
440 }
441}
442
443// Errs adds the field key with errs as an array of serialized errors to the
444// *Event context.

Callers 7

ErrMethod · 0.95
TestWithFunction · 0.45
TestFieldsFunction · 0.45
TestFieldsDisabledFunction · 0.45
TestEvent_AnErrFunction · 0.45
appendSlogAttrFunction · 0.45

Calls 5

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

Tested by 5

TestWithFunction · 0.36
TestFieldsFunction · 0.36
TestFieldsDisabledFunction · 0.36
TestEvent_AnErrFunction · 0.36