Skip to content
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

Migrate to slog #3376

Merged
merged 25 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 17 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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ require (
go.uber.org/atomic v1.11.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
go.uber.org/zap/exp v0.1.1-0.20240913022758-ede8e1888f83
golang.org/x/crypto v0.27.0
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0
golang.org/x/mod v0.21.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
go.uber.org/zap/exp v0.1.1-0.20240913022758-ede8e1888f83 h1:wpjRiPjppWaUIH+GC0bRvsdaH2K4Dw49dEJa7MX01Mk=
go.uber.org/zap/exp v0.1.1-0.20240913022758-ede8e1888f83/go.mod h1:5I384qq7XGxYyByIhHm6jg5CHkGY0nsTfbDLgDDlgJQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
Expand Down
19 changes: 10 additions & 9 deletions private/buf/bufctl/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"io"
"io/fs"
"log/slog"
"net/http"
"sort"

Expand Down Expand Up @@ -48,7 +49,6 @@ import (
"github.com/bufbuild/buf/private/pkg/syserror"
"github.com/bufbuild/protovalidate-go"
"go.uber.org/multierr"
"go.uber.org/zap"
"google.golang.org/protobuf/proto"
)

Expand Down Expand Up @@ -131,7 +131,7 @@ type Controller interface {
}

func NewController(
logger *zap.Logger,
logger *slog.Logger,
container app.EnvStdioContainer,
graphProvider bufmodule.GraphProvider,
moduleKeyProvider bufmodule.ModuleKeyProvider,
Expand Down Expand Up @@ -166,7 +166,7 @@ func NewController(
// it out again. The separation of concerns here is that the controller doesnt itself
// deal in the global variables.
type controller struct {
logger *zap.Logger
logger *slog.Logger
container app.EnvStdioContainer
moduleDataProvider bufmodule.ModuleDataProvider
graphProvider bufmodule.GraphProvider
Expand All @@ -188,7 +188,7 @@ type controller struct {
}

func newController(
logger *zap.Logger,
logger *slog.Logger,
container app.EnvStdioContainer,
graphProvider bufmodule.GraphProvider,
moduleKeyProvider bufmodule.ModuleKeyProvider,
Expand Down Expand Up @@ -1016,10 +1016,11 @@ func (c *controller) buildTargetImageWithConfigs(
modules := bufmodule.ModuleSetTargetModules(workspace)
imageWithConfigs := make([]ImageWithConfig, 0, len(modules))
for _, module := range modules {
c.logger.Debug(
c.logger.DebugContext(
ctx,
"building image for target module",
zap.String("moduleOpaqueID", module.OpaqueID()),
zap.String("moduleDescription", module.Description()),
slog.String("moduleOpaqueID", module.OpaqueID()),
slog.String("moduleDescription", module.Description()),
)
opaqueID := module.OpaqueID()
// We need to make sure that all dependencies are non-targets, so that they
Expand Down Expand Up @@ -1137,14 +1138,14 @@ func (c *controller) warnUnconfiguredTransitiveImports(
continue
}
if _, ok := configuredModuleFullNameStringMap[moduleFullNameString]; !ok {
c.logger.Sugar().Warnf(
c.logger.Warn(fmt.Sprintf(
`File %q imports %q, which is not in your workspace or in the dependencies declared in your buf.yaml, but is found in transitive dependency %q.
Declare %q in the deps key in your buf.yaml.`,
imageFile.Path(),
importPath,
moduleFullNameString,
moduleFullNameString,
)
))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions private/buf/bufcurl/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ package bufcurl

import (
"context"
"log/slog"

"github.com/bufbuild/buf/private/bufpkg/bufimage"
"github.com/bufbuild/buf/private/bufpkg/bufmodule"
"github.com/bufbuild/buf/private/gen/data/datawkt"
"github.com/bufbuild/buf/private/pkg/protoencoding"
"go.uber.org/zap"
"google.golang.org/protobuf/reflect/protoreflect"
)

Expand Down Expand Up @@ -103,7 +103,7 @@ func (c *combinedResolver) ListServices() ([]protoreflect.FullName, error) {
}

// NewWKTResolver returns a Resolver that can resolve all well-known types.
func NewWKTResolver(ctx context.Context, logger *zap.Logger) (Resolver, error) {
func NewWKTResolver(ctx context.Context, logger *slog.Logger) (Resolver, error) {
moduleSet, err := bufmodule.NewModuleSetBuilder(
ctx,
logger,
Expand Down
30 changes: 15 additions & 15 deletions private/buf/buffetch/buffetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"errors"
"fmt"
"io"
"log/slog"
"net/http"

"github.com/bufbuild/buf/private/buf/buffetch/internal"
Expand All @@ -30,7 +31,6 @@ import (
"github.com/bufbuild/buf/private/pkg/httpauth"
"github.com/bufbuild/buf/private/pkg/storage/storageos"
"github.com/bufbuild/buf/private/pkg/stringutil"
"go.uber.org/zap"
)

const (
Expand Down Expand Up @@ -243,12 +243,12 @@ type RefParser interface {
// NewRefParser returns a new RefParser.
//
// This defaults to dir or module.
func NewRefParser(logger *zap.Logger) RefParser {
func NewRefParser(logger *slog.Logger) RefParser {
return newRefParser(logger)
}

// NewMessageRefParser returns a new RefParser for messages only.
func NewMessageRefParser(logger *zap.Logger, options ...MessageRefParserOption) MessageRefParser {
func NewMessageRefParser(logger *slog.Logger, options ...MessageRefParserOption) MessageRefParser {
return newMessageRefParser(logger, options...)
}

Expand All @@ -267,29 +267,29 @@ func MessageRefParserWithDefaultMessageEncoding(defaultMessageEncoding MessageEn
// NewSourceRefParser returns a new RefParser for sources only.
//
// This defaults to dir.
func NewSourceRefParser(logger *zap.Logger) SourceRefParser {
func NewSourceRefParser(logger *slog.Logger) SourceRefParser {
return newSourceRefParser(logger)
}

// NewDirRefParser returns a new RefParser for dirs only.
func NewDirRefParser(logger *zap.Logger) DirRefParser {
func NewDirRefParser(logger *slog.Logger) DirRefParser {
return newDirRefParser(logger)
}

// NewDirOrProtoFileRefParser returns a new RefParser for dirs only.
func NewDirOrProtoFileRefParser(logger *zap.Logger) DirOrProtoFileRefParser {
func NewDirOrProtoFileRefParser(logger *slog.Logger) DirOrProtoFileRefParser {
return newDirOrProtoFileRefParser(logger)
}

// NewModuleRefParser returns a new RefParser for modules only.
func NewModuleRefParser(logger *zap.Logger) ModuleRefParser {
func NewModuleRefParser(logger *slog.Logger) ModuleRefParser {
return newModuleRefParser(logger)
}

// NewSourceOrModuleRefParser returns a new RefParser for sources or modules only.
//
// This defaults to dir or module.
func NewSourceOrModuleRefParser(logger *zap.Logger) SourceOrModuleRefParser {
func NewSourceOrModuleRefParser(logger *slog.Logger) SourceOrModuleRefParser {
return newSourceOrModuleRefParser(logger)
}

Expand Down Expand Up @@ -423,7 +423,7 @@ type Reader interface {

// NewReader returns a new Reader.
func NewReader(
logger *zap.Logger,
logger *slog.Logger,
storageosProvider storageos.Provider,
httpClient *http.Client,
httpAuthenticator httpauth.Authenticator,
Expand All @@ -442,7 +442,7 @@ func NewReader(

// NewMessageReader returns a new MessageReader.
func NewMessageReader(
logger *zap.Logger,
logger *slog.Logger,
storageosProvider storageos.Provider,
httpClient *http.Client,
httpAuthenticator httpauth.Authenticator,
Expand All @@ -459,7 +459,7 @@ func NewMessageReader(

// NewSourceReader returns a new SourceReader.
func NewSourceReader(
logger *zap.Logger,
logger *slog.Logger,
storageosProvider storageos.Provider,
httpClient *http.Client,
httpAuthenticator httpauth.Authenticator,
Expand All @@ -476,7 +476,7 @@ func NewSourceReader(

// NewDirReader returns a new DirReader.
func NewDirReader(
logger *zap.Logger,
logger *slog.Logger,
storageosProvider storageos.Provider,
) DirReader {
return newDirReader(
Expand All @@ -487,7 +487,7 @@ func NewDirReader(

// NewModuleFetcher returns a new ModuleFetcher.
func NewModuleFetcher(
logger *zap.Logger,
logger *slog.Logger,
storageosProvider storageos.Provider,
moduleKeyProvider bufmodule.ModuleKeyProvider,
) ModuleFetcher {
Expand All @@ -510,7 +510,7 @@ type Writer interface {

// NewWriter returns a new Writer.
func NewWriter(
logger *zap.Logger,
logger *slog.Logger,
) Writer {
return newWriter(
logger,
Expand All @@ -529,7 +529,7 @@ type ProtoFileWriter interface {

// NewProtoFileWriter returns a new ProtoFileWriter.
func NewProtoFileWriter(
logger *zap.Logger,
logger *slog.Logger,
) ProtoFileWriter {
return newProtoFileWriter(
logger,
Expand Down
9 changes: 5 additions & 4 deletions private/buf/buffetch/buffetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ package buffetch
import (
"context"
"io"
"log/slog"
"path/filepath"
"testing"

"github.com/bufbuild/buf/private/buf/buffetch/internal"
"github.com/bufbuild/buf/private/pkg/app"
"github.com/bufbuild/buf/private/pkg/slogext"
"github.com/bufbuild/buf/private/pkg/storage/storageos"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)

func TestRoundTripBin(t *testing.T) {
Expand Down Expand Up @@ -100,7 +101,7 @@ func testRoundTripLocalFile(
expectedFormat string,
expectedCompressionType internal.CompressionType,
) {
logger := zap.NewNop()
logger := slogext.NopLogger
refParser := newRefParser(logger)
reader := testNewFetchReader(logger)
writer := testNewFetchWriter(logger)
Expand Down Expand Up @@ -133,7 +134,7 @@ func testRoundTripLocalFile(
require.Equal(t, string(expectedData), string(actualData))
}

func testNewFetchReader(logger *zap.Logger) internal.Reader {
func testNewFetchReader(logger *slog.Logger) internal.Reader {
storageosProvider := storageos.NewProvider(storageos.ProviderWithSymlinks())
return internal.NewReader(
logger,
Expand All @@ -142,7 +143,7 @@ func testNewFetchReader(logger *zap.Logger) internal.Reader {
)
}

func testNewFetchWriter(logger *zap.Logger) internal.Writer {
func testNewFetchWriter(logger *slog.Logger) internal.Writer {
return internal.NewWriter(
logger,
internal.WithWriterLocal(),
Expand Down
10 changes: 5 additions & 5 deletions private/buf/buffetch/internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"io"
"log/slog"
"net/http"
"strconv"

Expand All @@ -29,7 +30,6 @@ import (
"github.com/bufbuild/buf/private/pkg/httpauth"
"github.com/bufbuild/buf/private/pkg/storage"
"github.com/bufbuild/buf/private/pkg/storage/storageos"
"go.uber.org/zap"
)

const (
Expand Down Expand Up @@ -400,7 +400,7 @@ type RefParser interface {
}

// NewRefParser returns a new RefParser.
func NewRefParser(logger *zap.Logger, options ...RefParserOption) RefParser {
func NewRefParser(logger *slog.Logger, options ...RefParserOption) RefParser {
return newRefParser(logger, options...)
}

Expand Down Expand Up @@ -462,7 +462,7 @@ type Reader interface {

// NewReader returns a new Reader.
func NewReader(
logger *zap.Logger,
logger *slog.Logger,
storageosProvider storageos.Provider,
options ...ReaderOption,
) Reader {
Expand All @@ -486,7 +486,7 @@ type Writer interface {

// NewWriter returns a new Writer.
func NewWriter(
logger *zap.Logger,
logger *slog.Logger,
options ...WriterOption,
) Writer {
return newWriter(
Expand All @@ -507,7 +507,7 @@ type ProtoFileWriter interface {

// NewProtoWriter returns a new ProtoWriter.
func NewProtoFileWriter(
logger *zap.Logger,
logger *slog.Logger,
) ProtoFileWriter {
return newProtoFileWriter(
logger,
Expand Down
6 changes: 3 additions & 3 deletions private/buf/buffetch/internal/proto_file_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ import (
"errors"
"fmt"
"io"
"log/slog"
"os"

"github.com/bufbuild/buf/private/pkg/app"
"github.com/bufbuild/buf/private/pkg/ioext"
"github.com/bufbuild/buf/private/pkg/normalpath"
"go.uber.org/zap"
)

type protoFileWriter struct {
logger *zap.Logger
logger *slog.Logger
}

func newProtoFileWriter(
logger *zap.Logger,
logger *slog.Logger,
) *protoFileWriter {
return &protoFileWriter{
logger: logger,
Expand Down
Loading
Loading