Documentation
¶
Overview ¶
Package ginzap provides log handling using zap package. Code structure based on ginrus package.
Index ¶
- func CustomRecoveryWithZap(logger ZapLogger, stack bool, recovery gin.RecoveryFunc) gin.HandlerFunc
- func Ginzap(logger ILogger, timeFormat string, utc bool) http.HandlerFunc
- func GinzapWithConfig(logger ILogger, conf *Config) http.HandlerFunc
- func RecoveryWithZap(logger ZapLogger, stack bool) gin.HandlerFunc
- type Config
- type Fn
- type IConfigOptionsFunction
- type ILogFieldInput
- type ILogger
- type Iconfigs
- type LogFieldInput
- type Logger
- func (l *Logger) Debug(ctx context.Context, message string, fieldData ...ILogFieldInput)
- func (l *Logger) Error(ctx context.Context, message string, fieldData ...ILogFieldInput)
- func (l *Logger) GetGrpcUnaryInterceptor() grpc.UnaryServerInterceptor
- func (l *Logger) GetIoWriter() io.Writer
- func (l *Logger) Info(ctx context.Context, message string, fieldData ...ILogFieldInput)
- func (l *Logger) RequestLog(request *http.Request)
- func (l *Logger) Sync()
- func (l *Logger) Warn(ctx context.Context, message string, fieldData ...ILogFieldInput)
- type ZapLogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CustomRecoveryWithZap ¶
func CustomRecoveryWithZap(logger ZapLogger, stack bool, recovery gin.RecoveryFunc) gin.HandlerFunc
CustomRecoveryWithZap returns a gin.HandlerFunc (middleware) with a custom recovery handler 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 Ginzap ¶
func Ginzap(logger ILogger, timeFormat string, utc bool) http.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:
- A time package format string (e.g. time.RFC3339).
- A boolean stating whether to use UTC time zone or local.
func GinzapWithConfig ¶
func GinzapWithConfig(logger ILogger, conf *Config) http.HandlerFunc
GinzapWithConfig returns a gin.HandlerFunc using configs
func RecoveryWithZap ¶
func RecoveryWithZap(logger ZapLogger, 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 { TimeFormat string UTC bool SkipPaths []string Context Fn DefaultLevel zapcore.Level }
Config is config setting for Ginzap
type IConfigOptionsFunction ¶
type IConfigOptionsFunction func(*configs)
type ILogFieldInput ¶
type ILogFieldInput interface { GetFieldName() string GetField() interface{} }
func NewLogFieldInput ¶
func NewLogFieldInput(fieldName string, fields interface{}) ILogFieldInput
type ILogger ¶
type ILogger interface { Sync() Debug(ctx context.Context, message string, fieldData ...ILogFieldInput) Info(ctx context.Context, message string, fieldData ...ILogFieldInput) Warn(ctx context.Context, message string, fieldData ...ILogFieldInput) Error(ctx context.Context, message string, fieldData ...ILogFieldInput) GetIoWriter() io.Writer RequestLog(request *http.Request) GetGrpcUnaryInterceptor() grpc.UnaryServerInterceptor }
type Iconfigs ¶
type Iconfigs interface { WithFilename(filename string) WithMaxBackUp(maxBackUp int) WithMaxAge(maxAge int) WithIsLocalTime(isLocalTime bool) WithIsCompressed(isCompressed bool) IsProduction() bool FileName() string MaxAge() int MaxSize() int MaxBackups() int IslocalTime() bool IsCompressed() bool }
func NewlogConfigOptions ¶
func NewlogConfigOptions(isProduction bool, opts ...IConfigOptionsFunction) Iconfigs
type LogFieldInput ¶
type LogFieldInput struct {
// contains filtered or unexported fields
}
func (LogFieldInput) GetField ¶
func (i LogFieldInput) GetField() interface{}
func (LogFieldInput) GetFieldName ¶
func (i LogFieldInput) GetFieldName() string
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func (*Logger) Debug ¶
func (l *Logger) Debug(ctx context.Context, message string, fieldData ...ILogFieldInput)
func (*Logger) Error ¶
func (l *Logger) Error(ctx context.Context, message string, fieldData ...ILogFieldInput)
func (*Logger) GetGrpcUnaryInterceptor ¶
func (l *Logger) GetGrpcUnaryInterceptor() grpc.UnaryServerInterceptor
grpc logger
func (*Logger) GetIoWriter ¶
func (*Logger) Info ¶
func (l *Logger) Info(ctx context.Context, message string, fieldData ...ILogFieldInput)