diff --git a/internal/logging/klog.go b/internal/logging/klog.go index a56e60d2..b36413d7 100644 --- a/internal/logging/klog.go +++ b/internal/logging/klog.go @@ -7,48 +7,28 @@ import ( "flag" "fmt" "os" - "strings" "github.com/go-logr/logr" "k8s.io/klog/v2" ) -type KlogFilter func(msg string, keysAndValues ...interface{}) bool - -// SetFilteredKlogLogger sets log as the logger backend of klog, with debugLevel+3 as the -// klog verbosity level. If debugLevel is 0, only request throttling messages are -// logged. Further filters can be added to the logger by passing them as arguments. -// Those filters also only apply for debugLevel 0. -func SetFilteredKlogLogger(debugLevel int, log logr.Logger, preds ...KlogFilter) { +// SetKlogLogger sets log as the logger backend of klog, with debugLevel+3 as the +// klog verbosity level. +func SetKlogLogger(debugLevel int, log logr.Logger) { fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError) klog.InitFlags(fs) _ = fs.Parse([]string{fmt.Sprintf("--v=%d", debugLevel+3)}) //nolint:errcheck // we couldn't do anything here anyway - preds = append(preds, requestThrottlingFilter) - if debugLevel == 0 { - preds = nil - } - - klogr := logr.New(&klogFilter{LogSink: log.GetSink(), preds: preds}) + klogr := logr.New(&klogFilter{LogSink: log.GetSink()}) klog.SetLogger(klogr) } type klogFilter struct { logr.LogSink - preds []KlogFilter } func (l *klogFilter) Info(level int, msg string, keysAndValues ...interface{}) { - if len(l.preds) == 0 { - l.LogSink.Info(klogToLogrLevel(level), msg, keysAndValues...) - return - } - for _, pred := range l.preds { - if pred(msg, keysAndValues...) { - l.LogSink.Info(klogToLogrLevel(level), msg, keysAndValues...) - return - } - } + l.LogSink.Info(klogToLogrLevel(level), msg, keysAndValues...) } func (l *klogFilter) Enabled(_ int) bool { @@ -64,15 +44,8 @@ func klogToLogrLevel(klogLvl int) int { func (l *klogFilter) WithCallDepth(depth int) logr.LogSink { if delegate, ok := l.LogSink.(logr.CallDepthLogSink); ok { - return &klogFilter{LogSink: delegate.WithCallDepth(depth), preds: l.preds} + return &klogFilter{LogSink: delegate.WithCallDepth(depth)} } return l } - -// requestThrottlingFilter drops everything that is not a client-go throttling -// message, compare: -// https://github.com/kubernetes/client-go/blob/8c4efe8d079e405329f314fb789a41ac6af101dc/rest/request.go#L621 -func requestThrottlingFilter(msg string, _ ...interface{}) bool { - return strings.Contains(msg, "Waited for ") && strings.Contains(msg, " request: ") -} diff --git a/internal/upbound/context.go b/internal/upbound/context.go index 5fac6b2c..58336735 100644 --- a/internal/upbound/context.go +++ b/internal/upbound/context.go @@ -233,7 +233,9 @@ func NewFromFlags(f Flags, opts ...Option) (*Context, error) { //nolint:gocyclo // SetupLogging sets up the logger in controller-runtime and kube's klog func (c *Context) SetupLogging() { - logging.SetFilteredKlogLogger(c.DebugLevel, c.zl) + if c.DebugLevel > 1 { + logging.SetKlogLogger(c.DebugLevel, c.zl) + } ctrl.SetLogger(c.zl) }