Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultConfig = &Config{ Output: os.Stderr, Format: TextFormat, Flags: StdLogFlags, Options: &slog.HandlerOptions{ Level: slog.LevelInfo, AddSource: false, }, }
DefaultConfig is the default logger used by the Logger middleware. It writes logs to os.Stderr with the TextFormat and StdLogFlags. The log level is set to Info.
Functions ¶
func New ¶
func New(config *Config) rex.Middleware
New returns a new Logger middleware with the provided configuration. The logger needs access to status code and thus must apear before middleware wrapping the default response writer (like etags and Brotli)
Types ¶
type Config ¶
type Config struct { // Output is the destination for the log output. If nil, os.Stderr is used. Output io.Writer // Format is the format of the log output. Default is TextFormat. Format LogFormat // Flags is the flags to be used for logging. Default is StdLogFlags. Flags LogFlags // Skip is a slice of paths that should not be logged. Skip []string // SkipIf is a function that can be used to skip logging based on the request. // If it returns true, the request will not be logged. SkipIf func(r *http.Request) bool // Options is the options to be passed to the slog.Handler. Options *slog.HandlerOptions // Callback is a function that can be used to modify the arguments passed to the logger. // Forexample the request_id, user_id etc. Callback func(r *http.Request, args ...any) []any }
Config is a middleware that logs the request and response information.
func (*Config) Logger ¶
func (l *Config) Logger(next rex.HandlerFunc) rex.HandlerFunc
Logger is the middleware handler function for LoggerMiddleware.
Click to show internal directories.
Click to hide internal directories.