requestlog

package
v2.0.1 Latest Latest
Warning

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

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

Documentation

Overview

Package requestlog provides requestlog utilities.

Index

Constants

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

Variables

This section is empty.

Functions

This section is empty.

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.

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