AnErr adds the field key with serialized err to the logger context. If err is nil, no field is added.
(key string, err error)
| 181 | // AnErr adds the field key with serialized err to the logger context. |
| 182 | // If err is nil, no field is added. |
| 183 | func (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. |