Skip to content

Commit

Permalink
Remove deprecated back-compat things
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thockin committed May 16, 2021
1 parent d661831 commit 48db269
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 66 deletions.
20 changes: 10 additions & 10 deletions discard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion discard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 0 additions & 27 deletions logr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions logr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
26 changes: 0 additions & 26 deletions testing/null.go

This file was deleted.

0 comments on commit 48db269

Please sign in to comment.