MCPcopy
hub / github.com/sirupsen/logrus / TestCustomSorting

Function TestCustomSorting

text_formatter_test.go:571–600  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

569}
570
571func TestCustomSorting(t *testing.T) {
572 formatter := &TextFormatter{
573 DisableColors: true,
574 SortingFunc: func(keys []string) {
575 sort.Slice(keys, func(i, j int) bool {
576 if keys[j] == "prefix" {
577 return false
578 }
579 if keys[i] == "prefix" {
580 return true
581 }
582 return strings.Compare(keys[i], keys[j]) == -1
583 })
584 },
585 }
586
587 entry := &Entry{
588 Message: "Testing custom sort function",
589 Time: time.Now(),
590 Level: InfoLevel,
591 Data: Fields{
592 "test": "testvalue",
593 "prefix": "the application prefix",
594 "blablabla": "blablabla",
595 },
596 }
597 b, err := formatter.Format(entry)
598 require.NoError(t, err)
599 require.True(t, strings.HasPrefix(string(b), "prefix="), "format output is %q", string(b))
600}

Callers

nothing calls this directly

Calls 1

FormatMethod · 0.95

Tested by

no test coverage detected