Skip to content

Commit

Permalink
simpler logr.New() signature
Browse files Browse the repository at this point in the history
  • Loading branch information
thockin committed Apr 23, 2021
1 parent 0fdc879 commit f49d372
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/tab_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@ func NewTabLogger() logr.Logger {
sink := tabLogSink{
writer: tabwriter.NewWriter(os.Stderr, 40, 8, 2, '\t', 0),
}
return logr.New(0, sink)
return logr.New(sink)
}
2 changes: 1 addition & 1 deletion funcr/funcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func New(fn func(prefix, args string), opts Options) logr.Logger {
logCaller: opts.LogCaller,
verbosity: opts.Verbosity,
}
return logr.New(0, fnl)
return logr.New(fnl)
}

type Options struct {
Expand Down
5 changes: 2 additions & 3 deletions logr.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,9 @@ import (

// New returns a new Logger instance. This is primarily used by libraries
// implementing LogSink, rather than end users.
func New(level int, sink LogSink) Logger {
func New(sink LogSink) Logger {
logger := Logger{
level: level,
sink: sink,
sink: sink,
}
if withCallDepth, ok := sink.(CallDepthLogSink); ok {
logger.withCallDepth = withCallDepth
Expand Down
6 changes: 3 additions & 3 deletions logr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestContext(t *testing.T) {
}

sink := &testLogSink{}
logger := New(0, sink)
logger := New(sink)
lctx := NewContext(ctx, logger)
if out, err := FromContext(lctx); err != nil {
t.Errorf("unexpected error: %v", err)
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestWithCallDepth(t *testing.T) {
// Test an impl that does not support it.
t.Run("not supported", func(t *testing.T) {
in := &testLogSink{}
l := New(0, in)
l := New(in)
out := l.WithCallDepth(42)
if p := out.sink.(*testLogSink); p != in {
t.Errorf("expected output to be the same as input: got in=%p, out=%p", in, p)
Expand All @@ -97,7 +97,7 @@ func TestWithCallDepth(t *testing.T) {
// Test an impl that does support it.
t.Run("supported", func(t *testing.T) {
in := &testCallDepthLogSink{&testLogSink{}, 0}
l := New(0, in)
l := New(in)
out := l.WithCallDepth(42)
if out.sink.(*testCallDepthLogSink) == in {
t.Errorf("expected output to be different than input: got in=out=%p", in)
Expand Down

0 comments on commit f49d372

Please sign in to comment.