Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused findLevel function #3628

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading