Documentation ¶
Index ¶
- Variables
- func Debug(msg string, fields ...zap.Field)
- func DefaultTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
- func Error(msg string, fields ...zap.Field)
- func Fatal(msg string, fields ...zap.Field)
- func Ginzap(logger *zap.Logger) gin.HandlerFunc
- func Info(msg string, fields ...zap.Field)
- func NewEncoderConfig() zapcore.EncoderConfig
- func Recovery(logger *zap.Logger, stack bool) gin.HandlerFunc
- func Use(logger *zap.Logger)
- func Warn(msg string, fields ...zap.Field)
- type Config
Constants ¶
This section is empty.
Variables ¶
var (
// DefaultTimeFormat is the default time format used in logging
DefaultTimeFormat = "2006-01-02 15:04:05.000 -0700"
)
Functions ¶
func Debug ¶
Debug logs a message at DebugLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func DefaultTimeEncoder ¶
func DefaultTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
DefaultTimeEncoder serializes time.Time to a human-readable formatted string
func Error ¶
Error logs a message at ErrorLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func Fatal ¶
Fatal logs a message at FatalLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.
func Ginzap ¶
func Ginzap(logger *zap.Logger) 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:
- A time package format string (e.g. time.RFC3339).
- A boolean stating whether to use UTC time zone or local.
This function is modified from github.com/gin-contrib/zap.Ginzap
func Info ¶
Info logs a message at InfoLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func NewEncoderConfig ¶
func NewEncoderConfig() zapcore.EncoderConfig
NewEncoderConfig creates and returns a zapcore.EncoderConfig object
func Recovery ¶
func Recovery(logger *zap.Logger, stack bool) 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. This function is modified from github.com/gin-contrib/zap.RecoveryWithZap