logger

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompatiblePath

func CompatiblePath(osPath string) string

CompatiblePath 兼容性好的文件路径,主要为解决 windows 下 「couldn't open sink」 的问题 如果要处理 windows 下文件日志,建议最好使用本方法处理一下文件路径

func FormatFile

func FormatFile(format string) string

FormatFile 根据 format 格式化文件。 format 示例:Y%/m%/app_d%.log

func New

func New(config *Config) (*zap.SugaredLogger, error)

New 默认将错误及以上级别的日志,存入 error.log, 其他级别日志,存入 app.log

func NewDateRotate

func NewDateRotate(config *DateRotateConfig) (*zap.SugaredLogger, error)

func NewDateRotateTee

func NewDateRotateTee(config []*DateRotateConfig) (*zap.SugaredLogger, error)

NewDateRotateTee Level 以第 0 个 config 为准

func Struct2Slice

func Struct2Slice(detail interface{}) (data []interface{})

Struct2Slice 用于将结构体内容保存到日志中,为json的root节点。 示例:DefaultLogger.Errorw(tips, Struct2Slice(&detail)...)

Types

type Config

type Config struct {
	//存储路径
	Path string `yaml:"path"`
	//日志记录等级
	Level zapcore.Level `yaml:"level"`
	//是否同步输出到console
	ConsoleOutput bool
}

type DateRotateConfig

type DateRotateConfig struct {
	Config
	// 存储文件格式。如果为空,则使用 defaultDateRotateLogName
	// Y% 年,如 2021
	// m% 月,如 9
	// d% 日,如 1
	// H% 小时,如 10
	// i% 分,如 2
	// s% 秒,如 55
	Format string `yaml:"format"`
	// 文件最多多少M
	MaxSize int `yaml:"max_size"`
	// 文件最多保留多长时间
	MaxAge int `yaml:"max_age"`
	// 文件最多保留多少个文件
	MaxBackups int `yaml:"max_backups"`
	// 是否启用压缩
	Compress bool `yaml:"compress"`
	// 与 level 参数一样,用于限制可保存的日志级别
	// 优先级比 level 高
	LevelEnableFunc zap.LevelEnablerFunc
	// 重命名文件周期
	ChangeNameInterval time.Duration
}

type DateRotateLogger

type DateRotateLogger struct {
	// contains filtered or unexported fields
}

func (*DateRotateLogger) Write

func (d *DateRotateLogger) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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