Documentation ¶
Overview ¶
Package gzap provides log handling using zap package. Code structure based on ginrus package. see github.com/gin-contrib/zap
Index ¶
- Constants
- func Any(key string, value interface{}) func(c *gin.Context) zap.Field
- func Float64(key string, value float64) func(c *gin.Context) zap.Field
- func Int64(key string, value int64) func(c *gin.Context) zap.Field
- func Logger(logger *zap.Logger, opts ...Option) gin.HandlerFunc
- func Recovery(logger *zap.Logger, stack bool, opts ...Option) gin.HandlerFunc
- func String(key, value string) func(c *gin.Context) zap.Field
- func Uint64(key string, value uint64) func(c *gin.Context) zap.Field
- type Config
- type Option
- func WithBodyLimit(limit int) Option
- func WithCustomFields(fields ...func(c *gin.Context) zap.Field) Option
- func WithEnableBody(b bool) Option
- func WithFieldName(index int, name string) Option
- func WithSkipLogging(f func(c *gin.Context) bool) Option
- func WithSkipRequestBody(f func(c *gin.Context) bool) Option
- func WithSkipResponseBody(f func(c *gin.Context) bool) Option
- func WithUseLoggerLevel(f func(c *gin.Context) zapcore.Level) Option
Constants ¶
const ( FieldStatus = iota FieldMethod FieldPath FieldRoute FieldQuery FieldIP FieldUserAgent FieldLatency FieldRequestBody FieldResponseBody )
Indices for renaming field.
Variables ¶
This section is empty.
Functions ¶
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().
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 ¶ added in v0.0.10
WithBodyLimit optional custom request/response body limit. default: <=0, mean not limit
func WithCustomFields ¶
WithCustomFields optional custom field
func WithEnableBody ¶ added in v0.0.10
WithEnableBody optional custom enable request/response body.
func WithFieldName ¶ added in v0.1.2
WithFieldName optionally renames a log field. Example: `WithFieldName(gzap.FieldStatus, "httpStatusCode")`
func WithSkipLogging ¶ added in v0.0.6
WithSkipLogging optional custom skip logging option.
func WithSkipRequestBody ¶ added in v0.1.4
WithSkipRequestBody optional custom skip request body logging option.
func WithSkipResponseBody ¶ added in v0.1.4
WithSkipResponseBody optional custom skip response body logging option.