Documentation ¶
Index ¶
- func New(logger *slog.Logger, opts ...ConfigOption) gin.HandlerFunc
- type Config
- type ConfigOption
- func WithCustomFields(customFields CustomFields) ConfigOption
- func WithCustomRecovery(customRecovery gin.RecoveryFunc) ConfigOption
- func WithDefaultLevel(level slog.Level) ConfigOption
- func WithoutDefaultFields() ConfigOption
- func WithoutError() ConfigOption
- func WithoutRequest() ConfigOption
- func WithoutStack() ConfigOption
- type CustomFields
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(logger *slog.Logger, opts ...ConfigOption) gin.HandlerFunc
New returns a gin.HandlerFunc (middleware) that recovers from any panics and logs the panic using slog. It sets the HTTP status code to 500. By default, the log level is ERROR.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config represents the recovery middleware configuration.
type ConfigOption ¶
type ConfigOption func(*Config)
ConfigOption allows to customize the middleware config.
func WithCustomFields ¶
func WithCustomFields(customFields CustomFields) ConfigOption
WithCustomFields allows to set a custom function to add custom fields to the log line.
func WithCustomRecovery ¶
func WithCustomRecovery(customRecovery gin.RecoveryFunc) ConfigOption
WithCustomRecovery allows to set a custom recovery function.
func WithDefaultLevel ¶
func WithDefaultLevel(level slog.Level) ConfigOption
WithDefaultLevel allows to set the default log level.
func WithoutDefaultFields ¶
func WithoutDefaultFields() ConfigOption
WithoutDefaultFields to not use the default fields in the log line.
func WithoutRequest ¶
func WithoutRequest() ConfigOption
WithoutRequest to not log the request field.
Click to show internal directories.
Click to hide internal directories.