diff --git a/json_formatter.go b/json_formatter.go index b13f0cd..d3dadef 100644 --- a/json_formatter.go +++ b/json_formatter.go @@ -47,6 +47,9 @@ type JSONFormatter struct { // }, // } FieldMap FieldMap + + // PrettyPrint will indent all json logs + PrettyPrint bool } // Format renders a single log entry @@ -88,9 +91,14 @@ func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) { } else { 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 b.Bytes(), nil }