reqlog

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Miss = func(*xun.Context) string { return "-" }

Miss is a default function that returns an empty string. It is used as a default argument for the WithVisitor and WithUser functions.

Functions

func Combined

func Combined(c *xun.Context, options *Options, starts time.Time)

Combined log request with Combined Log Format (XLF/ELF)

func Common

func Common(c *xun.Context, options *Options, starts time.Time)

Common log request with Common Log Format (CLF)

func Escape added in v1.1.2

func Escape(s string) string

func IsHTTPs added in v1.1.2

func IsHTTPs(r *http.Request) bool

func New

func New(opts ...Option) xun.Middleware

New returns a middleware that logs each incoming request to the provided logger. The format of the log messages is customizable using the Format option. The default format is the combined log format (XLF/ELF).

func VCombined added in v1.1.2

func VCombined(c *xun.Context, options *Options, starts time.Time)

VCombined log request with Combined Log Format (XLF/ELF) with virtual host

Types

type Format

type Format func(c *xun.Context, options *Options, starts time.Time)

Format is a function type that takes a Context pointer, an Options pointer, and a time.Time as arguments. It is used to format log messages.

type Option

type Option func(o *Options)

Option is a function that takes a pointer to Options and modifies it. It is used to customize the behavior of the RequestLog middleware.

func WithFormat

func WithFormat(f Format) Option

WithFormat sets a custom format for the request log message.

func WithLogger

func WithLogger(l *log.Logger) Option

WithLogger sets the logger for the RequestLog middleware. If not set, it will use the package-level logger from the log package.

func WithSkip added in v1.1.2

func WithSkip(f func(c *xun.Context) bool) Option

WithSkip sets a custom function to skip the request log message. The function should take a pointer to the xun.Context and return a boolean. If the function returns true, the request log message will be skipped.

func WithUser

func WithUser(get func(c *xun.Context) string) Option

WithUser sets a custom function to retrieve user information from the request context. It will be used to populate the user field in the request log message.

The function should take a pointer to the xun.Context and return a string. The empty string will be replaced with a dash in the log message.

func WithVisitor

func WithVisitor(get func(c *xun.Context) string) Option

WithVisitor sets a custom function to retrieve visitor information from the request context. It will be used to populate the visitor field in the request log message.

The function should take a pointer to the xun.Context and return a string. The empty string will be replaced with a dash in the log message.

type Options

type Options struct {
	Logger     *log.Logger
	GetVisitor func(c *xun.Context) string
	GetUser    func(c *xun.Context) string
	Format     Format
	SkipFunc   func(c *xun.Context) bool
}

Options represents the configuration options for the RequestLog middleware. It allows customizing the request log message format, the logger instance, and the functions to retrieve visitor and user information from the request context.

Jump to

Keyboard shortcuts

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