Err adds the field "error" with serialized err to the logger context.
(err error)
| 207 | |
| 208 | // Err adds the field "error" with serialized err to the logger context. |
| 209 | func (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. |