forked from mirror/logrus
[JSON] Use type-switch for error field
This commit is contained in:
parent
7498110889
commit
98fd21de2c
|
@ -11,11 +11,12 @@ type JSONFormatter struct{}
|
|||
func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) {
|
||||
data := make(Fields, len(entry.Data)+3)
|
||||
for k, v := range entry.Data {
|
||||
// Otherwise errors are ignored by `encoding/json`
|
||||
// https://github.com/Sirupsen/logrus/issues/137
|
||||
if err, ok := v.(error); ok {
|
||||
data[k] = err.Error()
|
||||
} else {
|
||||
switch v := v.(type) {
|
||||
case error:
|
||||
// Otherwise errors are ignored by `encoding/json`
|
||||
// https://github.com/Sirupsen/logrus/issues/137
|
||||
data[k] = v.Error()
|
||||
default:
|
||||
data[k] = v
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue