fix(sdk): silence stdout logging via opt-in slog

The client SDK emitted 17 fmt.Printf / fmt.Println trace events directly to
stdout from KnowledgeQAStream and SearchKnowledge. Any consumer of the SDK —
the new CLI in particular — saw these lines interleaved with its own
output, breaking JSON envelope contracts and polluting human-mode tty.

Replace with a package-level slog logger. Default writes to io.Discard so
existing callers see no output change; set WEKNORA_SDK_DEBUG=1 to route
events to stderr for development.

No public SetLogger() API: the trace events were dev-only and a setter
would expand the SDK surface for a one-off use case.
This commit is contained in:
nullkey
2026-05-09 17:07:21 +08:00
committed by lyingbug
parent c8b2129853
commit fc694d5d21
2 changed files with 41 additions and 18 deletions
+20
View File
@@ -0,0 +1,20 @@
// Package client uses an opt-in slog logger for SDK-internal trace output.
// Default behavior writes to io.Discard so SDK consumers (CLI, server) never
// see SDK trace output on stdout/stderr. Set WEKNORA_SDK_DEBUG=1 to route
// trace events to stderr.
package client
import (
"io"
"log/slog"
"os"
)
var debugLogger = newDebugLogger()
func newDebugLogger() *slog.Logger {
if os.Getenv("WEKNORA_SDK_DEBUG") == "1" {
return slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug}))
}
return slog.New(slog.NewTextHandler(io.Discard, nil))
}