Documentation
¶
Overview ¶
Package gzap provides log handling using zap package.
Index ¶
- func Any(key string, value any) func(req *restful.Request, resp *restful.Response) zap.Field
- func Float64(key string, value float64) func(req *restful.Request, resp *restful.Response) zap.Field
- func Int64(key string, value int64) func(req *restful.Request, resp *restful.Response) zap.Field
- func Logger(logger *zap.Logger, opts ...Option) restful.FilterFunction
- func Recovery(logger *zap.Logger, stack bool, opts ...Option) restful.FilterFunction
- func String(key, value string) func(req *restful.Request, resp *restful.Response) zap.Field
- func Uint64(key string, value uint64) func(req *restful.Request, resp *restful.Response) zap.Field
- type Config
- type Option
- func WithBodyLimit(limit int) Option
- func WithCustomFields(fields ...func(req *restful.Request, resp *restful.Response) zap.Field) Option
- func WithEnableBody(b bool) Option
- func WithExternalEnableBody(b *atomic.Bool) Option
- func WithSkipLogging(f func(req *restful.Request, resp *restful.Response) bool) Option
- func WithSkipRequestBody(f func(req *restful.Request, resp *restful.Response) bool) Option
- func WithSkipResponseBody(f func(req *restful.Request, resp *restful.Response) bool) Option
- func WithUseLoggerLevel(f func(req *restful.Request, resp *restful.Response) zapcore.Level) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Float64 ¶
func Float64(key string, value float64) func(req *restful.Request, resp *restful.Response) zap.Field
Float64 custom immutable float32 field
func Logger ¶
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 ¶
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.
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 ¶
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 ¶
WithEnableBody optional custom enable request/response body.
func WithExternalEnableBody ¶
WithExternalEnableBody optional custom enable request/response body control by external itself.
func WithSkipLogging ¶
WithSkipLogging optional custom skip logging option.
func WithSkipRequestBody ¶
WithSkipRequestBody optional custom skip request body logging option.
func WithSkipResponseBody ¶
WithSkipResponseBody optional custom skip response body logging option.
func WithUseLoggerLevel ¶
WithUseLoggerLevel optional use logging level.