From 68c541ab34dfcfbd75ac96d8512073072840c1f5 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sun, 16 May 2021 16:31:59 -0700 Subject: [PATCH] Remove deprecated back-compat things DiscardLogger became a LogSink, so leaving that as a type was only needed for NullLogger. NullLogger can be completely replaced with Discard(). InfoLogger is vestigial and since this is a breaking change anyway, let's kill it off. Not that Logger is a type, we do not need WithCallDepth() as a standalone anymore. --- discard.go | 20 ++++++++++---------- discard_test.go | 2 +- logr.go | 27 --------------------------- logr_test.go | 4 ++-- testing/null.go | 26 -------------------------- 5 files changed, 13 insertions(+), 66 deletions(-) delete mode 100644 testing/null.go diff --git a/discard.go b/discard.go index 97e64c2..ec02a78 100644 --- a/discard.go +++ b/discard.go @@ -21,33 +21,33 @@ package logr func Discard() Logger { return Logger{ level: 0, - sink: DiscardLogger{}, + sink: discardLogger{}, } } -// DiscardLogger is a LogSink that discards all messages. -type DiscardLogger struct{} +// discardLogger is a LogSink that discards all messages. +type discardLogger struct{} // Verify that it actually implements the interface -var _ LogSink = DiscardLogger{} +var _ LogSink = discardLogger{} -func (l DiscardLogger) Init(RuntimeInfo) { +func (l discardLogger) Init(RuntimeInfo) { } -func (l DiscardLogger) Enabled(int) bool { +func (l discardLogger) Enabled(int) bool { return false } -func (l DiscardLogger) Info(int, string, ...interface{}) { +func (l discardLogger) Info(int, string, ...interface{}) { } -func (l DiscardLogger) Error(error, string, ...interface{}) { +func (l discardLogger) Error(error, string, ...interface{}) { } -func (l DiscardLogger) WithValues(...interface{}) LogSink { +func (l discardLogger) WithValues(...interface{}) LogSink { return l } -func (l DiscardLogger) WithName(string) LogSink { +func (l discardLogger) WithName(string) LogSink { return l } diff --git a/discard_test.go b/discard_test.go index 4bb1628..c1a6177 100644 --- a/discard_test.go +++ b/discard_test.go @@ -23,7 +23,7 @@ import ( func TestDiscard(t *testing.T) { l := Discard() - if _, ok := l.sink.(DiscardLogger); !ok { + if _, ok := l.sink.(discardLogger); !ok { t.Error("did not return the expected underlying type") } // Verify that none of the methods panic, there is not more we can test. diff --git a/logr.go b/logr.go index c0eb273..9ea027b 100644 --- a/logr.go +++ b/logr.go @@ -273,14 +273,6 @@ func (l Logger) WithCallDepth(depth int) Logger { return l } -// InfoLogger provides compatibility with code that relies on the v0.1.0 -// interface. -// -// Deprecated: InfoLogger is an artifact of early versions of this API. New -// users should never use it and existing users should use Logger instead. This -// will be removed in a future release. -type InfoLogger = Logger - // contextKey is how we find Loggers in a context.Context. type contextKey struct{} @@ -384,22 +376,3 @@ type CallDepthLogSink interface { // Successive calls to this are additive. WithCallDepth(depth int) LogSink } - -// WithCallDepth returns a Logger that will offset the call stack by the -// specified number of frames when logging call site information, if possible. -// This is useful for users who have helper functions between the "real" call -// site and the actual calls to Logger methods. If depth is 0 the attribution -// should be to the direct caller of this function. If depth is 1 the -// attribution should skip 1 call frame, and so on. Successive calls to this -// are additive. -// -// If the underlying log implementation supports a WithCallDepth(int) method, -// it will be called and the result returned. If the implementation does not -// support CallDepthLogSink, the original Logger will be returned. -// -// Deprecated: WithCallDepth is an artifact of early versions of this API. New -// users should never use it and existing users should use Logger.WithCallDepth -// instead. This will be removed in a future release. -func WithCallDepth(logger Logger, depth int) Logger { - return logger.WithCallDepth(depth) -} diff --git a/logr_test.go b/logr_test.go index 0d2b0d2..cb79a1b 100644 --- a/logr_test.go +++ b/logr_test.go @@ -55,8 +55,8 @@ func TestContext(t *testing.T) { t.Errorf("expected error, got %#v", out) } out := FromContextOrDiscard(ctx) - if _, ok := out.sink.(DiscardLogger); !ok { - t.Errorf("expected a DiscardLogger, got %#v", out) + if _, ok := out.sink.(discardLogger); !ok { + t.Errorf("expected a discardLogger, got %#v", out) } sink := &testLogSink{} diff --git a/testing/null.go b/testing/null.go deleted file mode 100644 index f5444b1..0000000 --- a/testing/null.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2019 The logr Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package testing - -import "github.com/go-logr/logr" - -// NullLogger is a logr.Logger that does nothing. -// -// Deprecated: NullLogger is idenitcal to logr.DiscardLogger. It is retained -// for backwards compatibility, but new users should use logr.DiscardLogger -// instead. -type NullLogger = logr.DiscardLogger