diff --git a/text_formatter.go b/text_formatter.go index e44f1e1..44b612d 100644 --- a/text_formatter.go +++ b/text_formatter.go @@ -46,15 +46,22 @@ type TextFormatter struct { // Enable logging the full timestamp when a TTY is attached instead of just // the time passed since beginning of execution. FullTimestamp bool + + // The fields are sorted by default for a consistent output. For applications + // that log extremely frequently and don't use the JSON formatter this may not + // be desired. + DisableSorting bool } func (f *TextFormatter) Format(entry *Entry) ([]byte, error) { - var keys []string = make([]string, 0, len(entry.Data)) for k := range entry.Data { keys = append(keys, k) } - sort.Strings(keys) + + if !f.DisableSorting { + sort.Strings(keys) + } b := &bytes.Buffer{} diff --git a/text_formatter_test.go b/text_formatter_test.go index 396bc5f..28a9499 100644 --- a/text_formatter_test.go +++ b/text_formatter_test.go @@ -32,3 +32,6 @@ func TestQuoting(t *testing.T) { checkQuoting(false, errors.New("invalid")) checkQuoting(true, errors.New("invalid argument")) } + +// TODO add tests for sorting etc., this requires a parser for the text +// formatter output.