Documentation
¶
Index ¶
- Constants
- func GetOrCreateRequestID(ctx *gin.Context) string
- func GetRequestLogger(ctx *gin.Context) *zap.Logger
- func GetSugaredRequestLogger(ctx *gin.Context) *zap.SugaredLogger
- func RequestLogger(logger *zap.Logger, opts ...RequestLoggerOption) gin.HandlerFunc
- type RequestLoggerConfig
- type RequestLoggerOption
Constants ¶
const ( RequestIDKey = logging.RequestIDKey RequestIDHeader = logging.RequestIDHeader RequestLoggerKey = logging.RequestLoggerKey )
Variables ¶
This section is empty.
Functions ¶
func GetOrCreateRequestID ¶
GetOrCreateRequestID returns the request ID of the supplied Gin context. If a request ID doesn't exist, then it creates and sets one.
func GetRequestLogger ¶
GetRequestLogger returns a logger for the current request context. By default, this only includes the request ID.
func GetSugaredRequestLogger ¶
func GetSugaredRequestLogger(ctx *gin.Context) *zap.SugaredLogger
GetSugaredRequestLogger is a shortcut for `GetRequestLogger(c).Sugar()`.
func RequestLogger ¶
func RequestLogger(logger *zap.Logger, opts ...RequestLoggerOption) gin.HandlerFunc
RequestLogger returns a Gin middleware for logging using Zap.
Types ¶
type RequestLoggerConfig ¶
type RequestLoggerConfig struct { // ExcludeQueryParameters controls whether query params are stripped off when logging. ExcludeQueryParameters bool `mapstructure:"exclude_query_parameters"` // LevelByPath sets a custom logging level by path. // e.g. "/api/v1/user/keys.pub" -> "debug". // Any other paths will be using default Info logging level LevelByPath map[string]string `mapstructure:"level_by_path"` // LevelByRegexPath sets a custom logging level by regex path. // e.g. "\\/api\\/v1\\/user/\\[a-zA-Z0-9_-]+\\/info" -> "debug". // Any other paths will be using default Info logging level LevelByRegexPath map[string]string `mapstructure:"level_by_regex_path"` }
RequestLoggerConfig is a config for RequestLogger.
func (RequestLoggerConfig) Opts ¶
func (rec RequestLoggerConfig) Opts() []RequestLoggerOption
Opts returns a set of opts to apply to RequestLogger constructor using this config.
func (RequestLoggerConfig) Validate ¶
func (rec RequestLoggerConfig) Validate() error
Validate RequestLoggerConfig.
type RequestLoggerOption ¶
type RequestLoggerOption func(*requestLogger)
RequestLoggerOption is a functional option pattern applied to configuring RequestLogger.
func WithRequestLoggerExcludeQueryParameters ¶
func WithRequestLoggerExcludeQueryParameters(value bool) RequestLoggerOption
WithRequestLoggerExcludeQueryParameters controls whether to exclude query parameters from logging.
By default, the query parameters are always logged.
func WithRequestLoggerLevelByPath ¶
func WithRequestLoggerLevelByPath(levelByPath map[string]zapcore.Level) RequestLoggerOption
WithRequestLoggerLevelByPath sets a custom logging level depending on path.
func WithRequestLoggerLevelByRegexPath ¶
func WithRequestLoggerLevelByRegexPath(levelByRegexPath map[*regexp.Regexp]zapcore.Level) RequestLoggerOption
WithRequestLoggerLevelByRegexPath sets a custom logging level depending on regex path.