fix: restore debug logging when debug=1 is set via DSN#1852
Open
wucm667 wants to merge 1 commit intoClickHouse:mainfrom
Open
fix: restore debug logging when debug=1 is set via DSN#1852wucm667 wants to merge 1 commit intoClickHouse:mainfrom
wucm667 wants to merge 1 commit intoClickHouse:mainfrom
Conversation
When debug=1 is set in the DSN (e.g., clickhouse://host/db?debug=1), no debug logs appeared in stdout. The root cause is that the logger() method required both Debug=true AND Debugf != nil to produce a working logger. When only debug=1 is set via DSN, Debugf is nil, so it fell through to the noop logger. This fix adds a fallback: when Debug=true but Debugf is nil, create a default slog.Logger that outputs to stdout at Debug level. Fixes ClickHouse#1835 Signed-off-by: wucm667 <stevenwucongmin@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1835
Summary
When
debug=1is set in the DSN (e.g.,clickhouse://host/db?debug=1), no debug logs appeared in stdout since v2.43.0.Root Cause
The
logger()method inclickhouse_options.gorequired bothDebug=trueANDDebugf != nilto produce a working logger. When onlydebug=1is set via DSN,Debugis set to true butDebugfremains nil, so the method fell through to the noop logger.Fix
Added a fallback in the
logger()method: whenDebug=truebutDebugfis nil, create a defaultslog.Loggerthat outputs to stdout at Debug level.Changes
clickhouse_options.go: Add default stdout logger fallback whenDebug=truewithoutDebugfclickhouse_options_test.go: AddTestLoggercovering 4 scenarios:debug=1via DSN produces non-noop loggerDebug=truewithDebugfuses legacy handler (backward compat)Loggeroption takes precedenceTesting
All tests pass, including existing
TestParseDSN,TestLegacyDebugfBackwardCompatibility, and newTestLogger.