Repository navigation
Logging EN
English | 简体中文
The SDK logs through log/slog. It logs nothing unless configured: without WithLogger and without TYPESAFE_LOG_LEVEL, records are discarded.
// Quick default: send info records to stderr.
// export TYPESAFE_LOG_LEVEL=debug
// Or own the handler with redaction:
logger := slog.New(typesafe.NewRedactingHandler(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
Level: slog.LevelDebug,
})))
client, err := typesafe.NewClient(typesafe.WithLogger(logger))ParseLogLevel(name) converts a name into a slog.Level:
| Name | Level |
|---|---|
debug |
slog.LevelDebug |
info |
slog.LevelInfo |
warn, warning
|
slog.LevelWarn |
error |
slog.LevelError |
off |
above every level; nothing is logged |
An unrecognized name is reported as invalid, and the SDK stays silent.
| Record | Level | Attributes |
|---|---|---|
response |
info |
method, url, status, elapsed_ms, request_id
|
request.retry |
info |
method, url, attempt
|
request.failed |
info |
method, url, error
|
request.wire |
debug |
method, url, headers, body
|
response headers and body |
debug | added to the info record when debug is enabled |
A response record:
time=2026-09-19T11:29:48.457+08:00 level=INFO msg=response method=POST url=https://api.typesafe.ai/v1/systemone status=200 elapsed_ms=484 request_id=req_01a0b7b6...
The SDK redacts credential-bearing headers from every record it logs. NewRedactingHandler extends the guarantee to records you route through the SDK's logger.
logger := slog.New(typesafe.NewRedactingHandler(slog.NewJSONHandler(os.Stdout, nil)))
client, err := typesafe.NewClient(typesafe.WithLogger(logger))A header counts as a credential when its name is one of Authorization, Proxy-Authorization, X-API-Key, API-Key, Cookie, or Set-Cookie, or when its name contains token or secret. Redacted values become ***:
msg=request.wire headers="map[Accept:application/json Authorization:*** User-Agent:typesafe-sdk-go/0.13.0]"
Warning
Headers are redacted; bodies are not. Keep credentials out of state, and prefer log levels below debug in production.
- 指南
- Guides