Skip to content

Commit

Permalink
Make custom debug log function on-par with the built-in one (#1317)
Browse files Browse the repository at this point in the history
  • Loading branch information
vespian authored Jun 4, 2024
1 parent f373529 commit 49e6265
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ func dial(ctx context.Context, addr string, num int, opt *Options) (*connect, er
}
if opt.Debug {
if opt.Debugf != nil {
debugf = opt.Debugf
debugf = func(format string, v ...any) {
opt.Debugf(
"[clickhouse][conn=%d][%s] "+format,
append([]interface{}{num, conn.RemoteAddr()}, v...)...,
)
}
} else {
debugf = log.New(os.Stdout, fmt.Sprintf("[clickhouse][conn=%d][%s]", num, conn.RemoteAddr()), 0).Printf
}
Expand Down
7 changes: 6 additions & 1 deletion conn_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ func dialHttp(ctx context.Context, addr string, num int, opt *Options) (*httpCon
var debugf = func(format string, v ...any) {}
if opt.Debug {
if opt.Debugf != nil {
debugf = opt.Debugf
debugf = func(format string, v ...any) {
opt.Debugf(
"[clickhouse][conn=%d][%s] "+format,
append([]interface{}{num, addr}, v...)...,
)
}
} else {
debugf = log.New(os.Stdout, fmt.Sprintf("[clickhouse][conn=%d][%s]", num, addr), 0).Printf
}
Expand Down

0 comments on commit 49e6265

Please sign in to comment.