Documentation
¶
Index ¶
- func Ctx(ctx context.Context) *zap.Logger
- func Default() *zap.Logger
- func Logger(ctx context.Context, config *configs.Config) error
- func New(opt ...Option) (*zap.Logger, error)
- func NewConsole(w io.Writer, level string) *zap.Logger
- func NewFileCore(level zapcore.Level, filename string) zapcore.Core
- func NewRotateFileCore(level zapcore.Level, filename string, cfg LogFileConfig) zapcore.Core
- func RegistryInitLogger(f InitLogger)
- func SetLogger(l *zap.Logger)
- func ToLevel(level string) zapcore.Level
- func With(fields ...zap.Field) *zap.Logger
- func WithContextField(ctx context.Context, fields ...zap.Field) context.Context
- func WithContextLogger(ctx context.Context, logger *zap.Logger) context.Context
- type Config
- type CtxLogger
- type InitLogger
- type LogFileConfig
- type Option
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewConsole ¶
NewConsole creates a logger suitable for short-lived CLI commands. Unlike the application logger, it does not require a config file and omits timestamps and caller information to keep terminal output concise.
func NewFileCore ¶
NewFileCore 按默认轮转参数创建写文件的日志 core。
func NewRotateFileCore ¶
NewRotateFileCore 按 cfg 里的轮转参数创建写文件的日志 core,cfg 中的文件名字段不参与。
func RegistryInitLogger ¶
func RegistryInitLogger(f InitLogger)
func WithContextField ¶
WithContextField 取出context中的日志实例并添加字段存入上下文 在想为后续操作添加字段时使用 logger.WithContextField(ctx, zap.String("key", "value"))
Types ¶
type Config ¶
type Config struct {
Level string
DisableConsole bool `yaml:"disableConsole"`
LogFile LogFileConfig `yaml:"logFile"`
}
type CtxLogger ¶
func NewCtxLogger ¶
type InitLogger ¶
type LogFileConfig ¶
type LogFileConfig struct {
Enable bool
Filename string
ErrorFilename string `yaml:"errorFilename"`
// 以下是 lumberjack 的轮转参数,Filename 与 ErrorFilename 共用。
// 零值沿用默认值,不配的应用行为与改动前一致。
// MaxSize 单个文件的大小上限(MB),默认 2
MaxSize int `yaml:"maxSize"`
// MaxBackups 保留的已轮转文件个数,默认 10;负数表示不按个数清理
MaxBackups int `yaml:"maxBackups"`
// MaxAge 已轮转文件的保留天数,默认 30;负数表示不按天数清理
MaxAge int `yaml:"maxAge"`
// Compress 是否把已轮转的文件 gzip 压缩
Compress bool `yaml:"compress"`
}