Help us shape the future of Go! Take the 2026 Go Developer Survey

logger

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package logger logs one line per request.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(configs ...Config) zinc.Middleware

New logs each request after the rest of the chain has run. A returned error is sent through the application's error handler first, so the logged status is the one the client received.

Types

type Config

type Config struct {
	// Logger receives the default log line. If nil, slog.Default() is used.
	Logger *slog.Logger
	// Log replaces the default log line. It receives every request's values.
	Log func(*zinc.Context, Values) error
	// Headers lists request headers to copy into Values.Headers.
	Headers []string
	// QueryParams lists query parameters to copy into Values.QueryParams.
	QueryParams []string
	// contains filtered or unexported fields
}

Config controls request logging. The zero value logs every request to slog.Default().

type Values

type Values struct {
	StartTime     time.Time
	Latency       time.Duration
	Method        string
	URI           string
	RoutePath     string
	Status        int
	Error         error
	RemoteIP      string
	Host          string
	UserAgent     string
	RequestID     string
	ContentLength string
	ResponseSize  int64
	Headers       map[string][]string
	QueryParams   map[string][]string
}

Values contains extracted request/response values.

Jump to

Keyboard shortcuts

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