Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StructuredLogger ¶
func StructuredLogger(opts ...Option) middleware.MiddlewareFunc
StructuredLogger creates middleware that logs request and response information using structured logging.
By default, it uses slog.Default() as the logger. A custom logger can be specified using the WithLogger option.
The middleware logs:
- Before handler execution: Request information (excluding Body, but including Body size)
- After handler execution: Response information (excluding Body, but including Body size), error if any, and execution duration
Example:
// Use with default logger handler := middleware.Use(myHandler, logger.StructuredLogger()) // Use with custom logger customLogger := slog.New(slog.NewJSONHandler(os.Stdout, nil)) handler := middleware.Use(myHandler, logger.StructuredLogger(WithLogger(customLogger)))
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config represents the configuration for the StructuredLogger middleware.
type Option ¶
type Option func(*Config)
Option is a function type to modify the StructuredLogger configuration.
func WithLogger ¶
WithLogger sets a custom logger for the StructuredLogger middleware.
func WithRequestBodyLogging ¶
WithRequestBodyLogging enables or disables request body logging in the middleware. By default, logging is disabled.
func WithResponseBodyLogging ¶
WithResponseBodyLogging enables or disables response body logging in the middleware. By default, logging is disabled.