Documentation
¶
Index ¶
- Constants
- func Closer(ctx context.Context, c io.Closer)
- func DumpHttpRequest(ctx context.Context, r *http.Request, level slog.Level, body bool)
- func DumpHttpResponse(ctx context.Context, r *http.Response, level slog.Level, body bool)
- func SetHumanReadableSubTypes(list []string)
- func SetTraceKey(key string)
- type TraceHandler
Constants ¶
const (
TraceCtxKey contextKey = iota + 1
)
Variables ¶
This section is empty.
Functions ¶
func DumpHttpRequest ¶
DumpHttpRequest logs the full HTTP request using slog at the specified log level. It uses DumpRequestOut for client requests and DumpRequest for server requests. If body is true and the Content-Type is human-readable, the body is included in the dump. If the body is binary, a placeholder is appended instead.
func DumpHttpResponse ¶
DumpHttpResponse logs the full HTTP response using slog at the specified log level. If body is true and the Content-Type is human-readable, the body is included in the dump. If the body is binary, a placeholder is appended instead.
func SetHumanReadableSubTypes ¶ added in v0.5.0
func SetHumanReadableSubTypes(list []string)
SetHumanReadableSubTypes overrides the list of application/* subtypes whose bodies are logged as text. It must be called before any concurrent use of DumpHttpRequest or DumpHttpResponse.
func SetTraceKey ¶
func SetTraceKey(key string)
SetTraceKey sets the key used to store trace IDs in log records. If a non-empty key is provided, it overrides the default trace key ("trace_id"). It must be called before any concurrent use of DumpHttpRequest or DumpHttpResponse.
Types ¶
type TraceHandler ¶
TraceHandler allows the slog to add a trace ID to logs from the context. To add a trace ID to the context, use TraceCtxKey:
ctx = context.WithValue(ctx, log.TraceCtxKey, 'your_id_here')