Merge branch 'master' of git://github.com/mariannefeng/logrus into mariannefeng-master

This commit is contained in:
David Bariod 2018-09-08 11:18:16 +02:00
commit f3df9aeffd
1 changed files with 10 additions and 2 deletions

View File

@ -47,6 +47,9 @@ type JSONFormatter struct {
// }, // },
// } // }
FieldMap FieldMap FieldMap FieldMap
// PrettyPrint will indent all json logs
PrettyPrint bool
} }
// Format renders a single log entry // Format renders a single log entry
@ -88,9 +91,14 @@ func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) {
} else { } else {
b = &bytes.Buffer{} b = &bytes.Buffer{}
} }
err := json.NewEncoder(b).Encode(data)
if err != nil { encoder := json.NewEncoder(b)
if f.PrettyPrint {
encoder.SetIndent("", " ")
}
if err := encoder.Encode(data); err != nil {
return nil, fmt.Errorf("Failed to marshal fields to JSON, %v", err) return nil, fmt.Errorf("Failed to marshal fields to JSON, %v", err)
} }
return b.Bytes(), nil return b.Bytes(), nil
} }