Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
211 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
Copyright 2022 VMware, Inc. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package reconcilers | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/go-logr/logr" | ||
) | ||
|
||
var ( | ||
_ logr.LogSink = (*warnOnceLogSink)(nil) | ||
) | ||
|
||
// Deprecated | ||
func newWarnOnceLogger(log logr.Logger) logr.Logger { | ||
return logr.New(&warnOnceLogSink{ | ||
sink: log.GetSink(), | ||
}) | ||
} | ||
|
||
// Deprecated | ||
type warnOnceLogSink struct { | ||
sink logr.LogSink | ||
once sync.Once | ||
} | ||
|
||
func (s *warnOnceLogSink) Init(info logr.RuntimeInfo) { | ||
s.warn() | ||
s.sink.Init(info) | ||
} | ||
|
||
func (s *warnOnceLogSink) Enabled(level int) bool { | ||
s.warn() | ||
return s.sink.Enabled(level) | ||
} | ||
|
||
func (s *warnOnceLogSink) Info(level int, msg string, keysAndValues ...interface{}) { | ||
s.warn() | ||
s.sink.Info(level, msg, keysAndValues...) | ||
} | ||
|
||
func (s *warnOnceLogSink) Error(err error, msg string, keysAndValues ...interface{}) { | ||
s.warn() | ||
s.sink.Error(err, msg, keysAndValues...) | ||
} | ||
|
||
func (s *warnOnceLogSink) WithValues(keysAndValues ...interface{}) logr.LogSink { | ||
s.warn() | ||
return s.sink.WithValues(keysAndValues...) | ||
} | ||
|
||
func (s *warnOnceLogSink) WithName(name string) logr.LogSink { | ||
s.warn() | ||
return s.sink.WithName(name) | ||
} | ||
|
||
func (s *warnOnceLogSink) warn() { | ||
s.once.Do(func() { | ||
s.sink.Info(0, "Config.Log is deprecated, use a logger from the context: `log := logr.FromContext(ctx)`") | ||
}) | ||
} |
Oops, something went wrong.