ClickHouse Logging Queries
chdebug
For quick debugging, you can print executed queries to stdout. First, you need to install chdebug
package:
go get github.com/uptrace/go-clickhouse/chdebug
Then add the provided query hook which by default only prints failed queries:
db := ch.Connect(ch.WithDatabase("test"))
db.AddQueryHook(chdebug.NewQueryHook(chdebug.WithVerbose(true)))
To print all queries, use WithVerbose
option:
chdebug.NewQueryHook(chdebug.WithVerbose(true))
You can also disable the hook by default and use environment variables to enable it when needed:
chdebug.NewQueryHook(
// disable the hook
chdebug.WithEnabled(false),
// CHDEBUG=1 logs failed queries
// CHDEBUG=2 logs all queries
chdebug.FromEnv("CHDEBUG"),
)