From 538395b333d25a59cce4e30b2a41da7354d10865 Mon Sep 17 00:00:00 2001 From: Simon Eskildsen Date: Mon, 9 Mar 2015 15:19:51 +0000 Subject: [PATCH] text_formatter: add field to disable sorting --- text_formatter.go | 11 +++++++++-- text_formatter_test.go | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) 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.