Skip to content

Remove references to deprecate slogr package #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
test:
strategy:
matrix:
go-versions: [ 1.18.x, 1.19.x, 1.20.x ]
go-version: [ 1.19.x, 1.20.x, 1.21.x ]
platform: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
6 changes: 3 additions & 3 deletions slog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"testing"
"testing/slogtest"

"github.com/go-logr/logr/slogr"
"github.com/go-logr/logr"
"github.com/go-logr/zapr"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
Expand All @@ -48,7 +48,7 @@ func TestSlogHandler(t *testing.T) {
core := zapcore.NewCore(encoder, zapcore.AddSync(&buffer), zapcore.Level(0))
zl := zap.New(core)
logger := zapr.NewLogger(zl)
handler := slogr.NewSlogHandler(logger)
handler := logr.ToSlogHandler(logger)

err := slogtest.TestHandler(handler, func() []map[string]any {
_ = zl.Sync()
Expand Down Expand Up @@ -157,7 +157,7 @@ func TestSlogCases(t *testing.T) {
core := zapcore.NewCore(encoder, zapcore.AddSync(&buffer), zapcore.Level(-10))
zl := zap.New(core)
logger := zapr.NewLoggerWithOptions(zl, zapr.LogInfoLevel("v"))
handler := slogr.NewSlogHandler(logger.V(tc.v))
handler := logr.ToSlogHandler(logger.V(tc.v))
require.NoError(t, handler.Handle(context.Background(), tc.record))
_ = zl.Sync()
require.JSONEq(t, tc.expected, buffer.String())
Expand Down
8 changes: 4 additions & 4 deletions slogzapr.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import (
"log/slog"
"runtime"

"github.com/go-logr/logr/slogr"
"github.com/go-logr/logr"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

var _ slogr.SlogSink = &zapLogger{}
var _ logr.SlogSink = &zapLogger{}

func (zl *zapLogger) Handle(_ context.Context, record slog.Record) error {
zapLevel := zap.InfoLevel
Expand Down Expand Up @@ -170,13 +170,13 @@ func pcToCallerEntry(pc uintptr) zapcore.EntryCaller {
}
}

func (zl *zapLogger) WithAttrs(attrs []slog.Attr) slogr.SlogSink {
func (zl *zapLogger) WithAttrs(attrs []slog.Attr) logr.SlogSink {
newLogger := *zl
newLogger.l = newLogger.l.With(zap.Inline(marshalAttrs(attrs)))
return &newLogger
}

func (zl *zapLogger) WithGroup(name string) slogr.SlogSink {
func (zl *zapLogger) WithGroup(name string) logr.SlogSink {
newLogger := *zl
newLogger.l = newLogger.l.With(zap.Namespace(name))
return &newLogger
Expand Down
3 changes: 1 addition & 2 deletions zapr_slog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"log/slog"

"github.com/go-logr/logr"
"github.com/go-logr/logr/slogr"
)

func hasSlog() bool {
Expand Down Expand Up @@ -71,7 +70,7 @@ func (v valuer) LogValue() slog.Value {
var _ slog.LogValuer = valuer{}

func logWithSlog(l logr.Logger, msg string, withKeysValues, keysValues []interface{}) {
logger := slog.New(slogr.NewSlogHandler(l))
logger := slog.New(logr.ToSlogHandler(l))
if withKeysValues != nil {
logger = logger.With(withKeysValues...)
}
Expand Down