verboselog

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package verboselog provides full request/response logging middleware for the aarv framework.

Unlike the standard logger plugin which logs metadata only, verboselog captures and logs:

  • Request: method, path, headers, query params, and body
  • Response: status, headers, and body

This is useful for debugging, auditing, and API monitoring. Use with caution in production as it may log sensitive data and has performance overhead from body buffering.

Usage:

// Enable JSON output for slog first
slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stdout, nil)))

app := aarv.New()
app.Use(verboselog.New())

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(config ...Config) aarv.Middleware

New creates a full request/response dump logger middleware.

Types

type Config

type Config struct {
	// SkipPaths is a list of URL paths to exclude from logging.
	SkipPaths []string

	// Level is the slog level used for logging.
	// Default: slog.LevelInfo.
	Level slog.Level

	// LogRequestBody enables logging of request body.
	// Default: true.
	LogRequestBody bool

	// LogResponseBody enables logging of response body.
	// Default: true.
	LogResponseBody bool

	// LogRequestHeaders enables logging of request headers.
	// Default: true.
	LogRequestHeaders bool

	// LogResponseHeaders enables logging of response headers.
	// Default: true.
	LogResponseHeaders bool

	// LogQueryParams enables logging of query parameters.
	// Default: true.
	LogQueryParams bool

	// LogClientIP enables logging of client IP address.
	// Default: true.
	LogClientIP bool

	// LogUserAgent enables logging of User-Agent header.
	// Default: true.
	LogUserAgent bool

	// LogContentInfo enables logging of content-type and content-length.
	// Default: true.
	LogContentInfo bool

	// LogLatencyMS enables logging of latency in milliseconds as float.
	// Default: true.
	LogLatencyMS bool

	// MaxBodySize is the maximum body size to log (in bytes).
	// Bodies larger than this are truncated with "[truncated]" marker.
	// Default: 64KB.
	MaxBodySize int

	// SensitiveHeaders is a list of header names to redact.
	// Values are replaced with "[REDACTED]".
	// Default: Authorization, Cookie, Set-Cookie, X-API-Key.
	SensitiveHeaders []string

	// SensitiveFields is a list of JSON field names to redact in body.
	// This is a simple string replacement - not full JSON parsing.
	// Default: password, token, secret, api_key, apikey.
	SensitiveFields []string

	// RedactSensitive enables sensitive data redaction.
	// Set to false to disable all redaction for maximum performance.
	// Default: true.
	RedactSensitive bool
}

Config holds configuration for the dump logger middleware.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default dump logger configuration.

func MinimalConfig

func MinimalConfig() Config

MinimalConfig returns a minimal configuration for maximum performance. Only logs method, path, status, and latency.

Jump to

Keyboard shortcuts

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