Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(config ...Config) fh.HandlerFunc
Types ¶
type Config ¶
type Config struct {
// Format is used when FormatName is empty or unknown.
//
// Supported tokens:
// ${time} ${ip} ${method} ${path} ${query} ${uri} ${status} ${latency} ${error}
Format string
// FormatName can be:
// default, common, combined, tiny, json
FormatName string
// TimeFormat defaults to time.RFC3339.
TimeFormat string
// Logger enables fh.Logger output (defaults to log/slog).
// If nil and Slog is nil and Writers is empty, fh.NewDefaultLogger() is used.
Logger fh.Logger
// Slog enables structured slog output.
Slog *slog.Logger
// SlogLevel defaults to slog.LevelInfo.
SlogLevel slog.Level
// Writers receives rendered text/json log lines.
// Writers are called only from the async worker.
Writers []io.Writer
// QueueSize defaults to 4096.
QueueSize int
// MaxLineBytes caps one rendered log line.
// Defaults to 4096. Larger logs are truncated.
MaxLineBytes int
// DropPolicy controls behavior when async queue is full.
// Default: DropNewest.
DropPolicy DropPolicy
// Skip allows custom skipping before logging.
// It runs before ctx.Next(). If true, no log is written.
Skip func(fh.Ctx) bool
// SkipAfter allows custom skipping after ctx.Next().
// Useful for status-code based rules.
SkipAfter func(fh.Ctx, error) bool
// SkipDefaultStatic skips common static asset types.
// Defaults to true.
SkipDefaultStatic bool
// SkipExtensions are matched case-insensitively.
// Example: []string{".css", ".js", ".png"}
SkipExtensions []string
// SkipPaths are exact path matches.
SkipPaths []string
// SkipPrefixes are prefix path matches.
SkipPrefixes []string
// SkipMethods are exact method matches.
SkipMethods []string
// SkipStatusCodes skips after request handling.
SkipStatusCodes []int
// IncludeQueryInPath makes ${path} include query string.
IncludeQueryInPath bool
// DisableAsync is not recommended.
// If true, writes are performed in request path.
DisableAsync bool
}
type DropPolicy ¶
type DropPolicy uint8
const ( // DropNewest drops the current log entry when queue is full. DropNewest DropPolicy = iota // DropOldest removes one queued entry and inserts the current one. DropOldest )
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
func NewMiddleware ¶
func NewMiddleware(config ...Config) *Middleware
func (*Middleware) Close ¶
func (m *Middleware) Close() error
func (*Middleware) Dropped ¶
func (m *Middleware) Dropped() uint64
func (*Middleware) Handler ¶
func (m *Middleware) Handler() fh.HandlerFunc
Click to show internal directories.
Click to hide internal directories.