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

This commit is contained in:
Marianne Feng 2017-11-30 23:11:56 -08:00
commit 1917d221a6
1 changed files with 12 additions and 1 deletions

View File

@ -43,6 +43,9 @@ type JSONFormatter struct {
// },
// }
FieldMap FieldMap
// PrettyPrint will indent all json logs
PrettyPrint bool
}
// Format renders a single log entry
@ -71,7 +74,15 @@ func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) {
data[f.FieldMap.resolve(FieldKeyMsg)] = entry.Message
data[f.FieldMap.resolve(FieldKeyLevel)] = entry.Level.String()
serialized, err := json.Marshal(data)
var serialized []byte
var err error
if f.PrettyPrint {
serialized, err = json.MarshalIndent(data, "", "\t")
} else {
serialized, err = json.Marshal(data)
}
if err != nil {
return nil, fmt.Errorf("Failed to marshal fields to JSON, %v", err)
}