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

Method Err

context.go:209–226  ·  view source on GitHub ↗

Err adds the field "error" with serialized err to the logger context.

(err error)

Source from the content-addressed store, hash-verified

207
208// Err adds the field "error" with serialized err to the logger context.
209func (c Context) Err(err error) Context {
210 if c.l.stack && ErrorStackMarshaler != nil {
211 switch m := ErrorStackMarshaler(err).(type) {
212 case nil:
213 return c // do nothing with nil errors
214 case LogObjectMarshaler:
215 c = c.Object(ErrorStackFieldName, m)
216 case error:
217 c = c.Str(ErrorStackFieldName, m.Error())
218 case string:
219 c = c.Str(ErrorStackFieldName, m)
220 default:
221 c = c.Interface(ErrorStackFieldName, m)
222 }
223 }
224
225 return c.AnErr(ErrorFieldName, err)
226}
227
228// Ctx adds the context.Context to the logger context. The context.Context is
229// not rendered in the error message, but is made available for hooks to use.

Callers

nothing calls this directly

Calls 5

ObjectMethod · 0.95
StrMethod · 0.95
InterfaceMethod · 0.95
AnErrMethod · 0.95
ErrorMethod · 0.45

Tested by

no test coverage detected