NamedError constructs a field that lazily stores err.Error() under the provided key. Errors which also implement fmt.Formatter (like those produced by github.com/pkg/errors) will also have their verbose representation stored under key+"Verbose". If passed a nil error, the field is a no-op. For the
(key string, err error)
| 42 | // For the common case in which the key is simply "error", the Error function |
| 43 | // is shorter and less repetitive. |
| 44 | func NamedError(key string, err error) Field { |
| 45 | if err == nil { |
| 46 | return Skip() |
| 47 | } |
| 48 | return Field{Key: key, Type: zapcore.ErrorType, Interface: err} |
| 49 | } |
| 50 | |
| 51 | type errArray []error |
| 52 |