Documentation
¶
Index ¶
- func CompatiblePath(osPath string) string
- func FormatFile(format string) string
- func New(config *Config) (*zap.SugaredLogger, error)
- func NewDateRotate(config *DateRotateConfig) (*zap.SugaredLogger, error)
- func NewDateRotateTee(config []*DateRotateConfig) (*zap.SugaredLogger, error)
- func Struct2Slice(detail interface{}) (data []interface{})
- type Config
- type DateRotateConfig
- type DateRotateLogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompatiblePath ¶
CompatiblePath 兼容性好的文件路径,主要为解决 windows 下 「couldn't open sink」 的问题 如果要处理 windows 下文件日志,建议最好使用本方法处理一下文件路径
func FormatFile ¶
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 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
}
Click to show internal directories.
Click to hide internal directories.