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