Skip to content

Commit

Permalink
pruned the sorted fields; finished middleware tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johnabass committed Jul 9, 2020
1 parent 4ab87fd commit a17c396
Show file tree
Hide file tree
Showing 5 changed files with 450 additions and 34 deletions.
33 changes: 0 additions & 33 deletions captureCore.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package sallust
import (
"sync"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

Expand Down Expand Up @@ -134,35 +133,3 @@ func NewCaptureCore(enc zapcore.Encoder, ws zapcore.WriteSyncer, enab zapcore.Le
Core: zapcore.NewCore(enc, ws, enab),
}
}

// SortableFields is a sortable slice of fields. Keeping a slice
// of fields sorted helps with comparisons, particular during tests.
type SortableFields []zap.Field

// Len returns the length of this slice
func (sf SortableFields) Len() int {
return len(sf)
}

// Less compares the two sorted fields consistently, struct field by struct field.
// NOTE: The Field.Interface is not used in this comparison. Ordinarily, this won't
// be an issue as Field.Key should be unique in a given log message. However, in cases
// where all other struct fields of zap.Field are equal, this method gives
// inconsistent results.
func (sf SortableFields) Less(i, j int) bool {
if sf[i].Key < sf[j].Key {
return true
} else if sf[i].Type < sf[j].Type {
return true
} else if sf[i].Integer < sf[j].Integer {
return true
} else if sf[i].String < sf[j].String {
return true
}

return false
}

func (sf SortableFields) Swap(i, j int) {
sf[i], sf[j] = sf[j], sf[i]
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/xmidt-org/sallust
go 1.14

require (
github.com/influxdata/influxdb v1.8.0
github.com/stretchr/testify v1.4.0
go.uber.org/zap v1.15.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
Expand Down
Loading

0 comments on commit a17c396

Please sign in to comment.