Skip to content

fix: preserve custom logger option and add WithStructuredLogging - #2712

Open
reginaldalfret wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
reginaldalfret:fix/preserve-custom-logger-option
Open

reginaldalfret wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
reginaldalfret:fix/preserve-custom-logger-option

Conversation

@reginaldalfret

Copy link
Copy Markdown

Description of changes

This change ensures that a custom logger supplied via the programmatic WithLogger option is preserved when CLI flags or configuration files specify --structured-logs or --quiet.

  1. Preserve custom logger:

    • Previously in loadConfig, c.logger was unconditionally re-assigned if c.conf.StructuredLogs or c.conf.Quiet was true, overwriting any custom cloudsql.Logger passed by the caller in WithLogger.
    • Added a customLogger indicator to Command set by WithLogger so that custom loggers take precedence over default logger instantiation.
  2. Add WithStructuredLogging() Option:

    • Added WithStructuredLogging() to cmd/options.go alongside WithQuietLogging() and WithDebugLogging(), allowing programmatic enablement of structured JSON logging.
  3. Regression Tests:

    • Added WithStructuredLogging test case to TestCommandOptions.
    • Added TestCommandOptionsOverridesCLI test cases verifying that WithLogger takes precedence when --structured-logs or --quiet flags are supplied.

Signed-off-by: reginaldalfret <reginaldalfret@gmail.com>
@reginaldalfret
reginaldalfret requested a review from a team as a code owner October 26, 2026 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants