log

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TraceCtxKey contextKey = iota + 1
)

Variables

This section is empty.

Functions

func Closer

func Closer(ctx context.Context, c io.Closer)

Closer calls the Close method and logs any error via slog.

func DumpHttpRequest

func DumpHttpRequest(ctx context.Context, r *http.Request, level slog.Level, body bool)

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

func DumpHttpResponse(ctx context.Context, r *http.Response, level slog.Level, body bool)

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

type TraceHandler struct {
	slog.Handler
}

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')

func (TraceHandler) Handle

func (h TraceHandler) Handle(ctx context.Context, r slog.Record) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL