Skip to content
Merged
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
4 changes: 1 addition & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
14 changes: 14 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
Loading