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
- func IsSensitiveFieldName(name string) bool
- func RedactPayloadFields(fields map[string]any) map[string]any
- func RedactPayloadFieldsDeep(fields map[string]any) map[string]any
- type Middleware
- type Option
- func With5xxStackLogging(enabled bool) Option
- func WithClock(clock ports.Clock) Option
- func WithRedactedHeaders(headers ...string) Option
- func WithRequestHeaders() Option
- func WithResolver(resolver identity.Resolver) Option
- func WithResponseHeaders() Option
- func WithRoutePattern(fn func(*http.Request) string) Option
- type Options
Constants ¶
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
IsSensitiveFieldName reports whether the field name should be treated as sensitive for request log payloads.
func RedactPayloadFields ¶ added in v2.1.0
RedactPayloadFields returns a copy of fields with common sensitive payload keys replaced by redactedValue.
Types ¶
type Middleware ¶
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
With5xxStackLogging controls whether handled 5xx responses include a stack trace.
func WithRedactedHeaders ¶
WithRedactedHeaders appends additional header names to redact.
func WithRequestHeaders ¶
func WithRequestHeaders() Option
WithRequestHeaders enables logging sanitized request headers.
func WithResolver ¶
WithResolver sets the trusted proxy resolver.
func WithResponseHeaders ¶
func WithResponseHeaders() Option
WithResponseHeaders enables logging sanitized response headers.