Documentation
¶
Overview ¶
Package zap provides a zap logger implementation for the logx package. It supports high-performance logging with features like log rotation, buffering, and structured logging.
Package zap provides configuration structures and utilities for the zap logger.
Index ¶
Constants ¶
View Source
const ( // ZapFormatJSON specifies JSON format for log output. ZapFormatJSON = "json" // ZapFormatText specifies plain text format for log output. ZapFormatText = "text" // ZapEncodeLevelLower encodes log levels in lowercase. ZapEncodeLevelLower = "lower" // ZapEncodeLevelLowerColor encodes log levels in lowercase with color. ZapEncodeLevelLowerColor = "lowerColor" // ZapEncodeLevelCap encodes log levels in uppercase. ZapEncodeLevelCap = "cap" // ZapEncodeLevelCapColor encodes log levels in uppercase with color. ZapEncodeLevelCapColor = "capColor" )
View Source
const LoggerKey loggerKey = "zapLogger"
LoggerKey is the context key for storing the logger.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BufferedWriteSyncer ¶
type BufferedWriteSyncer struct {
WriteSyncer zapcore.WriteSyncer
Size int
FlushInterval int
// contains filtered or unexported fields
}
BufferedWriteSyncer implements a buffered WriteSyncer
func (*BufferedWriteSyncer) Sync ¶
func (bws *BufferedWriteSyncer) Sync() error
Sync implements the zapcore.WriteSyncer interface
type Logger ¶
type Logger struct {
*zap.SugaredLogger
}
Logger wraps zap.SugaredLogger to implement the logx.Logger interface.
func (*Logger) NewContext ¶
NewContext add fields to the specified context
type ZapConfig ¶
type ZapConfig struct {
// Level specifies the minimum log level (debug, info, warn, error, fatal).
Level string `mapstructure:"level" yaml:"level"`
// Prefix specifies the log message prefix.
Prefix string `mapstructure:"prefix" yaml:"prefix"`
// Format specifies the log output format (json or text).
Format string `mapstructure:"format" yaml:"format"`
// Director specifies the directory where log files are stored.
Director string `mapstructure:"director" yaml:"director"`
// EncodeLevel specifies how to encode log levels.
EncodeLevel string `mapstructure:"encode-level" yaml:"encode-level"`
// StacktraceKey specifies the key for stacktrace in log output.
StacktraceKey string `mapstructure:"stacktrace-key" yaml:"stacktrace-key"`
// MaxAge specifies the maximum number of days to retain log files.
MaxAge int `mapstructure:"max-age" yaml:"max-age"`
// MaxSize specifies the maximum size of a log file in MB.
MaxSize int `mapstructure:"max-size" yaml:"max-size"`
// MaxBackups specifies the maximum number of log files to keep.
MaxBackups int `mapstructure:"max-backups" yaml:"max-backups"`
// ShowCaller determines whether to show the caller information.
ShowCaller bool `mapstructure:"show-caller" yaml:"show-caller"`
// LogInConsole determines whether to output logs to console.
LogInConsole bool `mapstructure:"log-in-console" yaml:"log-in-console"`
// LocalTime determines whether to use local time (true) or UTC time (false).
LocalTime bool `mapstructure:"local-time" yaml:"local-time"`
// Compress determines whether to compress rotated log files.
Compress bool `mapstructure:"compress" yaml:"compress"`
// BufferSize specifies the buffer size for performance optimization.
BufferSize int `mapstructure:"buffer-size" yaml:"buffer-size"`
// FlushInterval specifies the interval in seconds to flush the buffer.
FlushInterval int `mapstructure:"flush-interval" yaml:"flush-interval"`
}
ZapConfig holds the configuration for the zap logger.
func (*ZapConfig) TransportLevel ¶
TransportLevel get zapcore.Level
func (*ZapConfig) ZapEncodeLevel ¶
func (z *ZapConfig) ZapEncodeLevel() zapcore.LevelEncoder
ZapEncodeLevel get zapcore.LevelEncoder
Click to show internal directories.
Click to hide internal directories.