config

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func CloseLogFiles added in v1.0.0

func CloseLogFiles() error

CloseLogFiles 关掉 InitLogger 打开过的日志文件(之后再写会重新打开)。 测试结束时调用:Windows 上打开着的文件删不掉,t.TempDir() 的清理会失败。

func GetLogLevel added in v0.2.0

func GetLogLevel() string

GetLogLevel 获取当前日志级别

func SetLogLevel added in v0.2.0

func SetLogLevel(level string) error

SetLogLevel 动态设置日志级别

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) InitLogger

func (z *Zap) InitLogger() (*zap.Logger, error)

func (*Zap) PruneOldLogs added in v0.39.0

func (z *Zap) PruneOldLogs() error

PruneOldLogs 在启动时清理日志目录中超出保留策略的滚动备份文件。 lumberjack 仅在发生「滚动」时才执行清理;若进程频繁重启且单个日志流尚未达到 MaxSize,旧的带时间戳/压缩备份可能永久滞留。本函数做一次性补充清理: 对每个基础日志名(all/debug/info/error)的备份按时间倒序保留 MaxBackups 个, 并删除超过 MaxAge 天的备份。base 文件(如 all.log)本身永不删除。

func (*Zap) ZapEncodeLevel

func (z *Zap) ZapEncodeLevel() zapcore.LevelEncoder

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL