Skip to content

Commit

Permalink
fix: logr pkg too many params (#67)
Browse files Browse the repository at this point in the history
Fix issue in `logr` pkg where `log.Scoped` had too many argument calls.

Also fix corresponding tests as well as some slight cleaning for import sorting and spelling 🧹
  • Loading branch information
jdpleiness committed Apr 25, 2024
1 parent 5e85304 commit 431bcb6
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 94 deletions.
2 changes: 1 addition & 1 deletion logger.go
Expand Up @@ -73,7 +73,7 @@ type Logger interface {
// scope. To disable all output, you can use LogLevelNone.
//
// IncreaseLevel is only allowed to increase the level the Logger was initialized at -
// it has no affect if the preset level is higher than the inidcated level.
// it has no affect if the preset level is higher than the indicated level.
IncreaseLevel(scope string, description string, level Level) Logger
}

Expand Down
3 changes: 2 additions & 1 deletion logr/fields.go
@@ -1,8 +1,9 @@
package logr

import (
"github.com/sourcegraph/log"
"go.uber.org/zap"

"github.com/sourcegraph/log"
)

func toLogFields(keysAndValues []any) []log.Field {
Expand Down
3 changes: 2 additions & 1 deletion logr/fields_test.go
Expand Up @@ -3,8 +3,9 @@ package logr
import (
"testing"

"github.com/sourcegraph/log"
"github.com/stretchr/testify/assert"

"github.com/sourcegraph/log"
)

func TestToLogFields(t *testing.T) {
Expand Down
29 changes: 15 additions & 14 deletions logr/go.mod
Expand Up @@ -7,29 +7,30 @@ replace github.com/sourcegraph/log => ../
require (
github.com/go-logr/logr v1.2.3
github.com/sourcegraph/log v0.0.0-20230118185536-8e43a48b83a9
github.com/stretchr/testify v1.8.0
github.com/stretchr/testify v1.8.2
go.uber.org/zap v1.24.0
)

require (
github.com/cockroachdb/errors v1.9.0 // indirect
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f // indirect
github.com/cockroachdb/redact v1.1.3 // indirect
github.com/cockroachdb/errors v1.9.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/getsentry/sentry-go v0.13.0 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/getsentry/sentry-go v0.21.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/go-cmp v0.5.7 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
111 changes: 37 additions & 74 deletions logr/go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion logr/logger.go
Expand Up @@ -12,7 +12,7 @@ import (
func GetLogger(l logr.Logger) (log.Logger, bool) {
sink, ok := l.GetSink().(*LogSink)
if !ok {
return log.Scoped("logr", "new log.Logger created from logr.Logger"), false
return log.Scoped("logr"), false
}
return sink.Logger, true
}
3 changes: 2 additions & 1 deletion logr/logger_test.go
Expand Up @@ -3,8 +3,9 @@ package logr
import (
"testing"

"github.com/sourcegraph/log/logtest"
"github.com/stretchr/testify/assert"

"github.com/sourcegraph/log/logtest"
)

func TestGetLogger(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion logr/logr.go
Expand Up @@ -68,5 +68,5 @@ func (s LogSink) WithValues(keysAndValues ...any) logr.LogSink {
// WithName returns a new LogSink with the specified name appended. See
// Logger.WithName for more details.
func (s LogSink) WithName(name string) logr.LogSink {
return &LogSink{s.Logger.Scoped(name, "")}
return &LogSink{s.Logger.Scoped(name)}
}

0 comments on commit 431bcb6

Please sign in to comment.