fc694d5d21
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.
21 lines
581 B
Go
21 lines
581 B
Go
// 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))
|
|
}
|