Documentation
¶
Index ¶
- func GetConfigEncoder(cfg FormatConfig) zapcore.Encoder
- func GetConsoleEncoder(cfg FormatConfig) zapcore.Encoder
- func GetCoreSimple(cfg LogConfig) []zapcore.Core
- func GetDefaultZapLogger() *zap.Logger
- func GetEncoderCore(cfg LogConfig) []zapcore.Core
- func GetLevelLowThan(level zapcore.Level) zap.LevelEnablerFunc
- func GetLevelPriority(level zapcore.Level) zap.LevelEnablerFunc
- func GetLevelUpThan(level zapcore.Level) zap.LevelEnablerFunc
- func GetSizeWriter(cfg WriterConfig, level string) *lumberjack.Logger
- func GetTimeWriter(cfg WriterConfig, level string) *rotatelogs.RotateLogs
- func NewZapLogger(skip int, cfg LogConfig) *zap.Logger
- type FormatConfig
- type LogConfig
- type WriterConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetCoreSimple ¶
GetCoreSimple 获取Encoder的 zapcore.Core 只分为 info 和 error两个等级
func GetDefaultZapLogger ¶
func GetEncoderCore ¶
func GetLevelPriority ¶
func GetLevelPriority(level zapcore.Level) zap.LevelEnablerFunc
GetLevelPriority 根据 zapcore.Level 获取 zap.LevelEnablerFunc 相等才发布
func GetSizeWriter ¶
func GetSizeWriter(cfg WriterConfig, level string) *lumberjack.Logger
GetSizeWriter 按文件大小分割日志文件
func GetTimeWriter ¶
func GetTimeWriter(cfg WriterConfig, level string) *rotatelogs.RotateLogs
GetTimeWriter 按时间分割日志文件 runtime/log/2022-11 rotate库于2022.11.9开始不再更新
Types ¶
type FormatConfig ¶
type FormatConfig struct {
Prefix string //前缀
Format string
StacktraceKey string
LogInConsole bool
ShowLine bool
EncodeLevel zapcore.LevelEncoder
}
负责设置 encoding 的日志格式
func (FormatConfig) PrefixTimeEncoder ¶
func (m FormatConfig) PrefixTimeEncoder(t time.Time, encoder zapcore.PrimitiveArrayEncoder)
PrefixTimeEncoder 自定义带前缀日志输出时间格式
type LogConfig ¶
type LogConfig struct {
Level string `mapstructure:"level" json:"level" yaml:"level"` // 级别
Prefix string `mapstructure:"prefix" json:"prefix" yaml:"prefix"` // 日志前缀
Format string `mapstructure:"format" json:"format" yaml:"format"` // 输出
Director string `mapstructure:"director" json:"director" yaml:"director"` // 日志文件夹
EncodeLevel string `mapstructure:"encode-level" json:"encode-level" yaml:"encode-level"` // 编码级
StacktraceKey string `mapstructure:"stacktrace-key" json:"stacktrace-key" yaml:"stacktrace-key"` // 栈名
MaxAge int `mapstructure:"max-age" json:"max-age" yaml:"max-age"` // 日志留存时间
ShowLine bool `mapstructure:"show-line" json:"show-line" yaml:"show-line"` // 显示行
LogInConsole bool `mapstructure:"log-in-console" json:"log-in-console" yaml:"log-in-console"` // 输出控制台
}
func GetDefaultConfig ¶
func GetDefaultConfig() LogConfig
func (*LogConfig) GetEncoderConfig ¶
func (cfg *LogConfig) GetEncoderConfig() FormatConfig
func (*LogConfig) GetWriterConfig ¶
func (cfg *LogConfig) GetWriterConfig() WriterConfig
func (*LogConfig) TransportLevel ¶
TransportLevel 根据字符串转化为 zapcore.Level Author [SliverHorn](https://github.com/SliverHorn)
func (*LogConfig) ZapEncodeLevel ¶
func (cfg *LogConfig) ZapEncodeLevel() zapcore.LevelEncoder
ZapEncodeLevel 根据 EncodeLevel 返回 zapcore.LevelEncoder Author [SliverHorn](https://github.com/SliverHorn)
Click to show internal directories.
Click to hide internal directories.