text_formatter: add field to disable sorting

This commit is contained in:
Simon Eskildsen 2015-03-09 15:19:51 +00:00
parent 8287db7934
commit 538395b333
2 changed files with 12 additions and 2 deletions

View File

@ -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{}

View File

@ -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.