Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var AtomicLogLevel zap.AtomicLevel
AtomicLogLevel 全局动态日志级别,用于运行时调整
View Source
var DefaultZapConfig = Zap{ Directory: "logs", MaxSize: 10, MaxAge: 30, MaxBackups: 10, Compress: true, Level: "info", Format: "json", ShowLine: false, EncodeLevel: "CapitalColorLevelEncoder", StacktraceKey: "", LogInConsole: true, }
Functions ¶
Types ¶
type Zap ¶
type Zap struct {
Directory string `mapstructure:"directory" json:"directory" yaml:"directory"`
MaxSize int `mapstructure:"max_size" json:"max_size" yaml:"max_size"`
MaxAge int `mapstructure:"max_age" json:"max_age" yaml:"max_age"`
MaxBackups int `mapstructure:"max_backups" json:"max_backups" yaml:"max_backups"`
Compress bool `mapstructure:"compress" json:"compress" yaml:"compress"`
Level string `mapstructure:"level" json:"level" yaml:"level"` // debug info warn error
Format string `mapstructure:"format" json:"format" yaml:"format"`
EncodeLevel string `mapstructure:"encode_level" json:"encode_level" yaml:"encode_level"`
StacktraceKey string `mapstructure:"stacktrace_key" json:"stacktrace_key" yaml:"stacktrace_key"`
LogInConsole bool `mapstructure:"log_in_console" json:"log_in_console" yaml:"log_in_console"`
ShowLine bool `mapstructure:"show_line" json:"show_line" yaml:"show_line"`
}
func (*Zap) ApplyEnvOverrides ¶ added in v0.39.0
func (z *Zap) ApplyEnvOverrides()
ApplyEnvOverrides 在日志器构建前从环境变量读取可在 DB 就绪前生效的配置 (级别与是否输出控制台)。DB 中的滚动/保留配置在 InitRuntime 中二次重建时再应用。
func (*Zap) PruneOldLogs ¶ added in v0.39.0
PruneOldLogs 在启动时清理日志目录中超出保留策略的滚动备份文件。 lumberjack 仅在发生「滚动」时才执行清理;若进程频繁重启且单个日志流尚未达到 MaxSize,旧的带时间戳/压缩备份可能永久滞留。本函数做一次性补充清理: 对每个基础日志名(all/debug/info/error)的备份按时间倒序保留 MaxBackups 个, 并删除超过 MaxAge 天的备份。base 文件(如 all.log)本身永不删除。
func (*Zap) ZapEncodeLevel ¶
func (z *Zap) ZapEncodeLevel() zapcore.LevelEncoder
Click to show internal directories.
Click to hide internal directories.