Skip to content

fix: restore debug logging when debug=1 is set via DSN#1852

Open
wucm667 wants to merge 1 commit intoClickHouse:mainfrom
wucm667:fix/debug-dsn-logging
Open

fix: restore debug logging when debug=1 is set via DSN#1852
wucm667 wants to merge 1 commit intoClickHouse:mainfrom
wucm667:fix/debug-dsn-logging

Conversation

@wucm667
Copy link
Copy Markdown

@wucm667 wucm667 commented Apr 29, 2026

Fixes #1835

Summary

When debug=1 is 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 in clickhouse_options.go required both Debug=true AND Debugf != nil to produce a working logger. When only debug=1 is set via DSN, Debug is set to true but Debugf remains nil, so the method fell through to the noop logger.

Fix

Added a fallback in the logger() method: when Debug=true but Debugf is nil, create a default slog.Logger that outputs to stdout at Debug level.

Changes

  • clickhouse_options.go: Add default stdout logger fallback when Debug=true without Debugf
  • clickhouse_options_test.go: Add TestLogger covering 4 scenarios:
    • debug=1 via DSN produces non-noop logger
    • No debug flag produces noop logger
    • Debug=true with Debugf uses legacy handler (backward compat)
    • Custom Logger option takes precedence

Testing

go test -v -count=1 .

All tests pass, including existing TestParseDSN, TestLegacyDebugfBackwardCompatibility, and new TestLogger.

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>
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 29, 2026

CLA assistant check
All committers have signed the CLA.

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.

Debug logs missing in v2.43.0

2 participants