Documentation
¶
Index ¶
- Variables
- func Combined(c *xun.Context, options *Options, starts time.Time)
- func Common(c *xun.Context, options *Options, starts time.Time)
- func Escape(s string) string
- func IsHTTPs(r *http.Request) bool
- func New(opts ...Option) xun.Middleware
- func VCombined(c *xun.Context, options *Options, starts time.Time)
- type Format
- type Option
- type Options
Constants ¶
This section is empty.
Variables ¶
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 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).
Types ¶
type Format ¶
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 ¶
WithFormat sets a custom format for the request log message.
func WithLogger ¶
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
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 ¶
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 ¶
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.