From cde9f9d4b9d26897cd00ff31da66d4ec1c9a2db3 Mon Sep 17 00:00:00 2001 From: miampf Date: Mon, 22 Jan 2024 16:29:37 +0100 Subject: [PATCH] fixed issues detected by bazel check --- debugd/internal/debugd/logcollector/logcollector.go | 2 +- hack/bazel-deps-mirror/internal/mirror/mirror.go | 2 +- internal/attestation/attestation.go | 4 ++-- internal/grpc/grpclog/grpclog_test.go | 2 +- internal/logger/grpclogger.go | 4 ++-- internal/logger/log.go | 3 ++- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/debugd/internal/debugd/logcollector/logcollector.go b/debugd/internal/debugd/logcollector/logcollector.go index 82dd2e6c066..9723d102fdd 100644 --- a/debugd/internal/debugd/logcollector/logcollector.go +++ b/debugd/internal/debugd/logcollector/logcollector.go @@ -304,7 +304,7 @@ type cmdLogger struct { } func (c *cmdLogger) Write(p []byte) (n int, err error) { - c.logger.Info(fmt.Sprintf("%s", p)) + c.logger.Info(string(p)) return len(p), nil } diff --git a/hack/bazel-deps-mirror/internal/mirror/mirror.go b/hack/bazel-deps-mirror/internal/mirror/mirror.go index 9f6709bf52d..1593cc29882 100644 --- a/hack/bazel-deps-mirror/internal/mirror/mirror.go +++ b/hack/bazel-deps-mirror/internal/mirror/mirror.go @@ -224,7 +224,7 @@ func (m *Maintainer) put(ctx context.Context, hash string, data io.Reader) error m.log.Debug(fmt.Sprintf("DryRun: s3 put object {Bucket: %v, Key: %v}", m.bucket, key)) return nil } - m.log.Debug(fmt.Sprintf(fmt.Sprintf("Uploading object with hash %v to s3://%v/%v", hash, m.bucket, key))) + m.log.Debug(fmt.Sprintf("Uploading object with hash %v to s3://%v/%v", hash, m.bucket, key)) _, err := m.uploadClient.Upload(ctx, &s3.PutObjectInput{ Bucket: &m.bucket, Key: &key, diff --git a/internal/attestation/attestation.go b/internal/attestation/attestation.go index 68c68998a38..34ced9e434f 100644 --- a/internal/attestation/attestation.go +++ b/internal/attestation/attestation.go @@ -52,10 +52,10 @@ type Logger interface { // NOPLogger is a no-op implementation of [Logger]. type NOPLogger struct{} -// Infof is a no-op. +// Info is a no-op. func (NOPLogger) Info(string, ...interface{}) {} -// Warnf is a no-op. +// Warn is a no-op. func (NOPLogger) Warn(string, ...interface{}) {} // DeriveClusterID derives the cluster ID from a salt and secret value. diff --git a/internal/grpc/grpclog/grpclog_test.go b/internal/grpc/grpclog/grpclog_test.go index b35baaab871..704f1a92379 100644 --- a/internal/grpc/grpclog/grpclog_test.go +++ b/internal/grpc/grpclog/grpclog_test.go @@ -87,7 +87,7 @@ type spyLog struct { msgs []string } -func (f *spyLog) Debug(msg string, args ...any) { +func (f *spyLog) Debug(msg string, _ ...any) { f.msgs = append(f.msgs, msg) } diff --git a/internal/logger/grpclogger.go b/internal/logger/grpclogger.go index 4582f6666da..716b0e495f0 100644 --- a/internal/logger/grpclogger.go +++ b/internal/logger/grpclogger.go @@ -28,14 +28,14 @@ func replaceGRPCLogger(log *slog.Logger) { func (l *grpcLogger) log(level slog.Level, args ...interface{}) { var pcs [1]uintptr runtime.Callers(3, pcs[:]) - r := slog.NewRecord(time.Now(), slog.LevelInfo, fmt.Sprint(args...), pcs[0]) + r := slog.NewRecord(time.Now(), level, fmt.Sprint(args...), pcs[0]) _ = l.logger.Handler().Handle(context.Background(), r) } func (l *grpcLogger) logf(level slog.Level, format string, args ...interface{}) { var pcs [1]uintptr runtime.Callers(3, pcs[:]) - r := slog.NewRecord(time.Now(), slog.LevelInfo, fmt.Sprintf(format, args...), pcs[0]) + r := slog.NewRecord(time.Now(), level, fmt.Sprintf(format, args...), pcs[0]) _ = l.logger.Handler().Handle(context.Background(), r) } diff --git a/internal/logger/log.go b/internal/logger/log.go index 7b4a8e4adc3..54041869383 100644 --- a/internal/logger/log.go +++ b/internal/logger/log.go @@ -105,11 +105,12 @@ func middlewareLogger(l *slog.Logger) logging.Logger { panic(fmt.Sprintf("unknown level %v", lvl)) } - r := slog.NewRecord(time.Now(), level, fmt.Sprintf(msg, fields...), pcs[0]) + r := slog.NewRecord(time.Now(), level, fmt.Sprintf(msg, f), pcs[0]) _ = l.Handler().Handle(context.Background(), r) }) } +// NewTest creates a new slog.Logger that writes to a testing.T. func NewTest(t *testing.T) *slog.Logger { return slog.New(slog.NewTextHandler(testWriter{t: t}, nil)) }