From 2d8d5cb11c7a76668adfe827e1ebd45114eed092 Mon Sep 17 00:00:00 2001 From: Eric Stern Date: Wed, 7 Oct 2026 16:44:36 -0700 Subject: [PATCH 1/2] test: cover --structured-logs with --quiet --- cmd/root_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cmd/root_test.go b/cmd/root_test.go index e7d870485..e0aaa3066 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -28,6 +28,7 @@ import ( "time" "cloud.google.com/go/cloudsqlconn" + "github.com/GoogleCloudPlatform/cloud-sql-proxy/v2/internal/log" "github.com/GoogleCloudPlatform/cloud-sql-proxy/v2/internal/proxy" "github.com/google/go-cmp/cmp" "github.com/spf13/cobra" @@ -133,6 +134,19 @@ func TestUserAgent(t *testing.T) { } } +func TestStructuredLogsWithQuiet(t *testing.T) { + cmd, err := invokeProxyCommand( + []string{"--structured-logs", "--quiet", "proj:region:inst"}, + ) + if err != nil { + t.Fatalf("want error = nil, got = %v", err) + } + + if _, ok := cmd.logger.(*log.StructuredLogger); !ok { + t.Errorf("want logger = *log.StructuredLogger, got = %T", cmd.logger) + } +} + func TestNewCommandArguments(t *testing.T) { tcs := []struct { desc string From ce694291c86a6366008bf5806ac0f2bdf18a32f1 Mon Sep 17 00:00:00 2001 From: Eric Stern Date: Wed, 7 Oct 2026 16:44:43 -0700 Subject: [PATCH 2/2] fix: keep structured logs when --quiet is set --- cmd/root.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 76eeb8913..ec83469d4 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -666,9 +666,7 @@ func loadConfig(c *Command, args []string, opts []Option) error { // Handle logger separately from config if c.conf.StructuredLogs { c.logger = log.NewStructuredLogger(c.conf.Quiet) - } - - if c.conf.Quiet { + } else if c.conf.Quiet { c.logger = log.NewStdLogger(io.Discard, os.Stderr) }