Skip to content

Commit

Permalink
Remove unused findLevel function (#3628)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcastorina authored Nov 19, 2024
1 parent ea94b0b commit 1018e00
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 23 deletions.
12 changes: 0 additions & 12 deletions pkg/log/level.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package log

import (
"sort"

"github.com/go-logr/logr"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
Expand Down Expand Up @@ -32,12 +29,3 @@ func SetLevelForControl(control levelSetter, level int8) {
// For example setting the level to -2 below, means log.V(2) will be enabled.
control.SetLevel(zapcore.Level(-level))
}

// findLevel probes a logr.Logger to figure out what level it is at via binary
// search. We only search [0, 128), so worst case is ~7 checks.
func findLevel(logger logr.Logger) int8 {
sink := logger.GetSink()
return int8(sort.Search(128, func(i int) bool {
return !sink.Enabled(i)
}) - 1)
}
11 changes: 0 additions & 11 deletions pkg/log/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,6 @@ func splitLines(s string) []string {
return logLines
}

func TestFindLevel(t *testing.T) {
lvl := zap.NewAtomicLevel()
logger, _ := New("parent", WithConsoleSink(io.Discard, WithLeveler(lvl)))

for i := 0; i < 128; i++ {
i8 := int8(i)
SetLevelForControl(lvl, i8)
assert.Equal(t, i8, findLevel(logger))
}
}

func TestGlobalRedaction_Console(t *testing.T) {
oldState := globalRedactor
globalRedactor = &dynamicRedactor{
Expand Down

0 comments on commit 1018e00

Please sign in to comment.