chislog

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Logger

func Logger(logger Slogger, opts ...Option) func(next http.Handler) http.Handler

Logger returns a go-chi middleware that logs requests using the given Slogger.

Types

type Filter

type Filter func(r *http.Request) bool

type IPExtractor

type IPExtractor func(r *http.Request) string

type Option

type Option func(cfg *config)

func WithFilter

func WithFilter(f Filter) Option

WithFilter adds a filter to the list of filters used by the middleware. If any filter indicates to exclude a request then the request will not be logged. All filters must allow a request to be logged. If no filters are provided, then all requests are logged.

func WithIPExtractor

func WithIPExtractor(extractor IPExtractor) Option

WithIPExtractor takes a function that will be called on every request and the returned ip will be added to the log entry.

http.Request RemoteAddr is logged by default.

type Slogger

type Slogger interface {
	Log(ctx context.Context, level slog.Level, msg string, args ...any)
}

Jump to

Keyboard shortcuts

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