gin_zerolog

package
v0.0.0-...-9102f00 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilConfig = errors.New("app/logger/gin_zerolog config must not be nil")
)

Functions

func NewMiddleware

func NewMiddleware(rawConfig *Config) (gin.HandlerFunc, error)

NewMiddleware allows to use app/logger instead of the default gin-gonic logger. It creates a new gin middleware that can be used by gin. Usage example:

r := gin.New() // empty engine instead of the default one
ginZerologConfig := &gin_zerolog.Config{}
ginZerologMiddleware, err := gin_zerolog.NewMiddleware(ginZerologConfig)
if err != nil {
  panic("failed to create gin_zerolog middleware")
}
r.Use(ginZerologMiddleware)
r.Use(gin.Recovery()) // add the default recovery middleware

Types

type Config

type Config struct {
	SkipPaths      []string       `yaml:"skip_paths"`
	SkipPathRegexp *regexp.Regexp `yaml:"skip_path_regexp"`

	// DefaultLogLevel defines the log level for http response
	// codes in range [0..399].
	//
	// Possible values: ["trace", "debug", "info", "warn", "error", "fatal", "panic"]
	// or empty string for NoLevel.
	DefaultLogLevel string `yaml:"default_log_level"`

	// RequestErrorLogLevel defines the log level for http response
	// codes in range [400..499].
	//
	// Possible values: ["trace", "debug", "info", "warn", "error", "fatal", "panic"]
	// or empty string for NoLevel.
	RequestErrorLogLevel string `yaml:"request_error_log_level"`

	// InternalErrorLogLevel defines the log level for http response
	// codes 500 and above.
	//
	// Possible values: ["trace", "debug", "info", "warn", "error", "fatal", "panic"]
	// or empty string for NoLevel. The default is zerolog.WarnLevel.
	InternalErrorLogLevel string `yaml:"internal_error_log_level"`
}

func (*Config) Validate

func (c *Config) Validate() (*validatedConfig, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL