gzap

package
v0.0.1-rc5 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package gzap provides log handling using zap package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any

func Any(key string, value any) func(req *restful.Request, resp *restful.Response) zap.Field

Any custom immutable any field

func Float64

func Float64(key string, value float64) func(req *restful.Request, resp *restful.Response) zap.Field

Float64 custom immutable float32 field

func Int64

func Int64(key string, value int64) func(req *restful.Request, resp *restful.Response) zap.Field

Int64 custom immutable int64 field

func Logger

func Logger(logger *zap.Logger, opts ...Option) restful.FilterFunction

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().

func Recovery

func Recovery(logger *zap.Logger, stack bool, opts ...Option) restful.FilterFunction

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 String

func String(key, value string) func(req *restful.Request, resp *restful.Response) zap.Field

String custom immutable string field

func Uint64

func Uint64(key string, value uint64) func(req *restful.Request, resp *restful.Response) zap.Field

Uint64 custom immutable uint64 field

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 WithBodyLimit

func WithBodyLimit(limit int) Option

WithBodyLimit optional custom request/response body limit. default: <=0, mean not limit

func WithCustomFields

func WithCustomFields(fields ...func(req *restful.Request, resp *restful.Response) zap.Field) Option

WithCustomFields optional custom field

func WithEnableBody

func WithEnableBody(b bool) Option

WithEnableBody optional custom enable request/response body.

func WithExternalEnableBody

func WithExternalEnableBody(b *atomic.Bool) Option

WithExternalEnableBody optional custom enable request/response body control by external itself.

func WithSkipLogging

func WithSkipLogging(f func(req *restful.Request, resp *restful.Response) bool) Option

WithSkipLogging optional custom skip logging option.

func WithSkipRequestBody

func WithSkipRequestBody(f func(req *restful.Request, resp *restful.Response) bool) Option

WithSkipRequestBody optional custom skip request body logging option.

func WithSkipResponseBody

func WithSkipResponseBody(f func(req *restful.Request, resp *restful.Response) bool) Option

WithSkipResponseBody optional custom skip response body logging option.

func WithUseLoggerLevel

func WithUseLoggerLevel(f func(req *restful.Request, resp *restful.Response) zapcore.Level) Option

WithUseLoggerLevel optional use logging level.

Jump to

Keyboard shortcuts

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