diff --git a/json_formatter.go b/json_formatter.go index fb01c1b..e52ab17 100644 --- a/json_formatter.go +++ b/json_formatter.go @@ -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) }