zap

package
v0.0.0-...-8e399c3 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ginzap

func Ginzap(logger *zap.Logger, timeFormat string, utc bool) gin.HandlerFunc

Ginzap returns a gin.HandlerFunc (middleware) that logs requests using uber-go/zap.

Requests with errors are logged using zap.Error(). Requests without errors are logged using zap.Info().

It receives:

  1. A time package format string (e.g. time.RFC3339).
  2. A boolean stating whether to use UTC time zone or local.

func Logger

func Logger(logger *zap.Logger, opts ...Option) gin.HandlerFunc

Logger returns a gin.HandlerFunc (middleware) that logs requests using uber-go/zap.

Requests with errors are logged using zap.Error(). Requests without errors are logged using zap.Info().

Default option:

  1. A time package format string (e.g. time.RFC3339).(default time.RFC3339Nano)
  2. Use time zone.(e.g. utc time zone).(default local).
  3. Custom fields.(default nil)

func Recovery

func Recovery(logger *zap.Logger, stack bool, opts ...Option) gin.HandlerFunc

Recovery returns a gin.HandlerFunc (middleware) that recovers from any panics and logs requests using uber-go/zap. All errors are logged using zap.Error(). stack means whether output the stack info. The stack info is easy to find where the error occurs but the stack info is too large.

func RecoveryWithZap

func RecoveryWithZap(logger *zap.Logger, stack bool) gin.HandlerFunc

RecoveryWithZap returns a gin.HandlerFunc (middleware) that recovers from any panics and logs requests using uber-go/zap. All errors are logged using zap.Error(). stack means whether output the stack info. The stack info is easy to find where the error occurs but the stack info is too large.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config logger/recover config

type Option

type Option func(c *Config)

Option logger/recover option

func WithBody

func WithBody(b bool) Option

func WithCustomFields

func WithCustomFields(fields ...func(c *gin.Context) zap.Field) Option

WithCustomFields optional custom field

func WithTimeFormat

func WithTimeFormat(layout string) Option

WithTimeFormat optional a time package format string (e.g. time.RFC3339).(default time.RFC3339Nano).

func WithUTC

func WithUTC(b bool) Option

WithUTC a boolean stating whether to use UTC time zone or local.(default local).

Jump to

Keyboard shortcuts

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