Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
wangjian | e378e87392 | |
wangjian | ba6a18ff2e | |
wangjian | f95dfe1666 |
28
logger.go
28
logger.go
|
@ -15,17 +15,17 @@ type ModOptions func(options *Options)
|
||||||
|
|
||||||
// Options 日志文件配置选项
|
// Options 日志文件配置选项
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Path string // 文件保存地方
|
Path string `yaml:"path" json:"path" toml:"path"` // 文件保存地方
|
||||||
Prefix string // 日志文件前缀
|
Prefix string `yaml:"prefix" json:"prefix" toml:"prefix"` // 日志文件前缀
|
||||||
ErrorFileSuffix string // error日志文件后缀
|
ErrorFileSuffix string `yaml:"errorFileSuffix" json:"errorFileSuffix" toml:"errorFileSuffix"` // error日志文件后缀
|
||||||
WarnFileSuffix string // warn日志文件后缀
|
WarnFileSuffix string `yaml:"warnFileSuffix" json:"warnFileSuffix" toml:"warnFileSuffix"` // warn日志文件后缀
|
||||||
InfoFileSuffix string // info日志文件后缀
|
InfoFileSuffix string `yaml:"infoFileSuffix" json:"infoFileSuffix" toml:"infoFileSuffix"` // info日志文件后缀
|
||||||
DebugFileSuffix string // debug日志文件后缀
|
DebugFileSuffix string `yaml:"debugFileSuffix" json:"debugFileSuffix" toml:"debugFileSuffix"` // debug日志文件后缀
|
||||||
Level zapcore.Level // 日志等级
|
Level zapcore.Level `yaml:"level" json:"level" toml:"level"` // 日志等级
|
||||||
MaxSize int // 日志文件大小(M)
|
MaxSize int `yaml:"maxSize" json:"maxSize" toml:"maxSize"` // 日志文件大小(M)
|
||||||
MaxBackups int // 最多存在多少个切片文件
|
MaxBackups int `yaml:"maxBackups" json:"maxBackups" toml:"maxBackups"` // 最多存在多少个切片文件
|
||||||
MaxAge int // 保存的最大天数
|
MaxAge int `yaml:"maxAge" json:"maxAge" toml:"maxAge"` // 保存的最大天数
|
||||||
Development bool // 是否是开发模式
|
Development bool `yaml:"development" json:"development" toml:"development"` // 是否是开发模式
|
||||||
zap.Config
|
zap.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ type Logger struct {
|
||||||
initialized bool
|
initialized bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLogger(mod ...ModOptions) *zap.Logger {
|
func NewLogger(mod ...ModOptions) *Logger {
|
||||||
logger = &Logger{}
|
logger = &Logger{}
|
||||||
logger.Lock()
|
logger.Lock()
|
||||||
defer logger.Unlock()
|
defer logger.Unlock()
|
||||||
|
@ -90,7 +90,7 @@ func NewLogger(mod ...ModOptions) *zap.Logger {
|
||||||
logger.zapConfig.Level.SetLevel(logger.Opts.Level)
|
logger.zapConfig.Level.SetLevel(logger.Opts.Level)
|
||||||
logger.init()
|
logger.init()
|
||||||
logger.initialized = true
|
logger.initialized = true
|
||||||
return logger.Logger
|
return logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func (logger *Logger) init() {
|
func (logger *Logger) init() {
|
||||||
|
@ -218,7 +218,7 @@ func (logger *Logger) cores() zap.Option {
|
||||||
FunctionKey: zapcore.OmitKey,
|
FunctionKey: zapcore.OmitKey,
|
||||||
MessageKey: "msg",
|
MessageKey: "msg",
|
||||||
StacktraceKey: "stacktrace",
|
StacktraceKey: "stacktrace",
|
||||||
LineEnding: " ",
|
LineEnding: "\n",
|
||||||
EncodeLevel: encodeLevel,
|
EncodeLevel: encodeLevel,
|
||||||
EncodeTime: encodeTime,
|
EncodeTime: encodeTime,
|
||||||
EncodeDuration: zapcore.SecondsDurationEncoder,
|
EncodeDuration: zapcore.SecondsDurationEncoder,
|
||||||
|
|
Loading…
Reference in New Issue