requestlog

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Panic logging ------------

Recovered panics are always emitted at error level. Panic observations use failure status metadata (5xx) in log fields while preserving the committed status in `committed_status` when a response had already started. Enable `With5xxStackLogging(true)` to capture stack traces for recovered panics.

Index

Constants

View Source
const (
	FieldRequestID       = "request_id"
	FieldTraceID         = "trace_id"
	FieldSpanID          = "span_id"
	FieldRoute           = "route"
	FieldStatus          = "status"
	FieldCommittedStatus = "committed_status"
	FieldLatencyMS       = "latency_ms"
	FieldMethod          = "method"
	FieldPath            = "path"
	FieldBytes           = "bytes"
	FieldClientIP        = "client_ip"
	FieldUserAgent       = "user_agent"
	FieldRequestHeaders  = "req_headers"
	FieldResponseHeaders = "resp_headers"
	FieldStack           = "stack"
	FieldPanicRecovered  = "panic_recovered"
)

Variables

This section is empty.

Functions

func IsSensitiveFieldName added in v2.1.0

func IsSensitiveFieldName(name string) bool

IsSensitiveFieldName reports whether the field name should be treated as sensitive for request log payloads.

func RedactPayloadFields added in v2.1.0

func RedactPayloadFields(fields map[string]any) map[string]any

RedactPayloadFields returns a copy of fields with common sensitive payload keys replaced by redactedValue.

func RedactPayloadFieldsDeep added in v2.1.0

func RedactPayloadFieldsDeep(fields map[string]any) map[string]any

RedactPayloadFieldsDeep returns a copy of fields with sensitive payload keys replaced by redactedValue. Nested maps and slices are sanitized recursively.

Types

type Middleware

type Middleware struct {
	Log ports.Logger
	// contains filtered or unexported fields
}

Middleware logs structured request summaries.

func New

func New(log ports.Logger, opts ...Option) (*Middleware, error)

New constructs a request logging middleware.

func (*Middleware) Handler

func (m *Middleware) Handler(next http.Handler) http.Handler

Handler wraps the next handler with request logging. It is intended to emit exactly one request log entry on both normal and panic paths. For panic paths, it should infer the final visible status before re-panicking so outer recovery can still produce the response contract.

func (*Middleware) Middleware

func (m *Middleware) Middleware() func(http.Handler) http.Handler

Middleware implements ports.Middleware via Handler adapter.

type Option

type Option func(*Options)

Option mutates request log options.

func With5xxStackLogging added in v2.1.0

func With5xxStackLogging(enabled bool) Option

With5xxStackLogging controls whether handled 5xx responses include a stack trace.

func WithClock

func WithClock(clock ports.Clock) Option

WithClock overrides the time source used for latency measurement.

func WithRedactedHeaders

func WithRedactedHeaders(headers ...string) Option

WithRedactedHeaders appends additional header names to redact.

func WithRequestHeaders

func WithRequestHeaders() Option

WithRequestHeaders enables logging sanitized request headers.

func WithResolver

func WithResolver(resolver identity.Resolver) Option

WithResolver sets the trusted proxy resolver.

func WithResponseHeaders

func WithResponseHeaders() Option

WithResponseHeaders enables logging sanitized response headers.

func WithRoutePattern

func WithRoutePattern(fn func(*http.Request) string) Option

WithRoutePattern sets the route pattern function for logging.

type Options

type Options struct {
	Resolver           identity.Resolver
	RoutePattern       func(*http.Request) string
	LogRequestHeaders  bool
	LogResponseHeaders bool
	Log5xxStacks       bool
	RedactHeaders      []string
	Clock              ports.Clock
}

Options configures request logging behavior.

Jump to

Keyboard shortcuts

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