Documentation
¶
Index ¶
- func GetDefLogDir(subDir string) (string, error)
- func GetDefLogFile(subDir string, logFileName string) (string, error)
- func GetLogDirFromFile(file string) string
- func GetLogFileFromFile(file string, logFileName string) string
- func NewDefLogger(level types.ILogLevel, logFile string) (logger types.ILogger, err error)
- func NewLogger(options ...OptionFunc) (types.ILogger, error)
- func NewSimpleLogger(options ...OptionFunc) types.ILogger
- func PrepareLogFolder(file string)
- type ILogFile
- type LogAppender
- type LogAppenderCfg
- type LogModule
- type Logger
- func (l *Logger) Debug(args ...any)
- func (l *Logger) Debugf(format string, args ...any)
- func (l *Logger) Debugw(msg string, keysAndValues ...any)
- func (l *Logger) Error(args ...any)
- func (l *Logger) Errorf(format string, args ...any)
- func (l *Logger) Errorw(msg string, keysAndValues ...any)
- func (l *Logger) Fatal(args ...any)
- func (l *Logger) Fatalf(format string, args ...any)
- func (l *Logger) Fatalw(msg string, keysAndValues ...any)
- func (l *Logger) Info(args ...any)
- func (l *Logger) Infof(format string, args ...any)
- func (l *Logger) Infow(msg string, keysAndValues ...any)
- func (l *Logger) Init() error
- func (l *Logger) Panic(args ...any)
- func (l *Logger) Panicf(format string, args ...any)
- func (l *Logger) Panicw(msg string, args ...any)
- func (l *Logger) Sync() error
- func (l *Logger) Warn(args ...any)
- func (l *Logger) Warnf(format string, args ...any)
- func (l *Logger) Warnw(msg string, keysAndValues ...any)
- type Option
- type OptionFunc
- func WithConsoleAppender(appender LogAppender) OptionFunc
- func WithConsoleDisable(disabled bool) OptionFunc
- func WithConsoleLevel(level types.ILogLevel) OptionFunc
- func WithConsoleText(text bool) OptionFunc
- func WithDebugLevel() OptionFunc
- func WithErrorFile(infoFile, errFile string) OptionFunc
- func WithErrorLevel() OptionFunc
- func WithErrorRotation(infoFile, errFile string, maxSize, maxBackups, maxAge int) OptionFunc
- func WithField(key, value string) OptionFunc
- func WithFile(logFile string) OptionFunc
- func WithFileRotation(logFile string, maxSize, maxBackups, maxAge int) OptionFunc
- func WithInfoLevel() OptionFunc
- func WithLevel(level types.ILogLevel) OptionFunc
- func WithMaxAge(maxAge int) OptionFunc
- func WithMaxBackups(count int) OptionFunc
- func WithMaxSize(size int) OptionFunc
- func WithNoCaller(noCaller bool) OptionFunc
- func WithText(text bool) OptionFunc
- func WithTimeLayout(timeLayout string) OptionFunc
- func WithWarnLevel() OptionFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetDefLogDir ¶ added in v1.0.29
func GetDefLogFile ¶ added in v1.0.29
func GetLogDirFromFile ¶ added in v1.0.29
func GetLogFileFromFile ¶ added in v1.0.29
file is any file with full path format, log file will also created in the same folder
func NewDefLogger ¶ added in v1.0.29
NewLogger 创建新的日志器
func NewSimpleLogger ¶ added in v1.0.29
func NewSimpleLogger(options ...OptionFunc) types.ILogger
func PrepareLogFolder ¶ added in v1.0.29
func PrepareLogFolder(file string)
Types ¶
type LogAppenderCfg ¶
type LogAppenderCfg struct {
NoCaller *bool `yaml:"noCaller,omitempty"` // default false
Disabled *bool `yaml:"disabled,omitempty"` // disabled, default false
Text *bool `yaml:"text,omitempty"` // json or text format, default false
// int8 ? zapcore.Level yml格式化输出会输出debug这种字符串,parse然后得不到正确是数值,所以改用int8
// default is 0, means info level
Level *int8 `yaml:"level,omitempty"`
// 以下4个是 file 用的
Path string `yaml:"path,omitempty"` // file path, for file appender, useless for console
// 以下3个是 logrotate用的
MaxSize *int `json:"maxSize" yaml:"maxSize"` // 单个文件最大尺寸,默认单位 M
MaxAge *int `json:"maxAge" yaml:"maxAge"` // 最大保留时间,默认单位 day
MaxBackups *int `json:"maxBackups" yaml:"maxBackups"` // 最多保留 n 个备份
}
func GetDefLogAppenderCfg ¶ added in v0.1.108
func GetDefLogAppenderCfg(logFile string) *LogAppenderCfg
func InitLogAppenderCfg ¶ added in v0.1.108
func InitLogAppenderCfg(baseCfg *LogAppenderCfg, logAppenderCfg *LogAppenderCfg, defLogFile string) *LogAppenderCfg
type LogModule ¶
type LogModule struct {
File *LogAppenderCfg `yaml:"file,omitempty"` // for file appender
Console *LogAppenderCfg `yaml:"console,omitempty"` // for console appender
Appenders []LogAppenderCfg `yaml:"appenders,omitempty"` // other appenders
}
func GetDefLogCfg ¶
func InitLogModuleCfg ¶
func InitLogModuleCfg(baseCfg *LogModule, logModuleCfg *LogModule, moduleDefLogFile string) *LogModule
fill default data for log module, otherwise some value will be nil
type Logger ¶ added in v1.0.29
type Logger struct {
// contains filtered or unexported fields
}
Logger 日志器结构
type Option ¶
type Option struct {
NoCaller bool
Level types.ILogLevel
Text bool
Fields map[string]string
TimeLayout string
Console LogAppender
// rotate
MaxSize int // 最大文件大小(M byte),不为0, will 自动启用rotate
MaxBackups int // 最大备份文件数
MaxAge int // max keep time
// file
FilePath string // 日志文件路径
Dir string // 日志目录
Filename string // 日志文件名
// advance
InfoFile string
ErrFile string
}
type OptionFunc ¶ added in v1.0.29
type OptionFunc func(*Option)
OptionFunc custom setup config
func WithConsoleAppender ¶
func WithConsoleAppender(appender LogAppender) OptionFunc
func WithConsoleDisable ¶
func WithConsoleDisable(disabled bool) OptionFunc
WithConsoleDisable write log to os.Stdout or os.Stderr
func WithConsoleLevel ¶
func WithConsoleLevel(level types.ILogLevel) OptionFunc
func WithConsoleText ¶
func WithConsoleText(text bool) OptionFunc
func WithDebugLevel ¶
func WithDebugLevel() OptionFunc
WithDebugLevel only greater than 'level' will output
func WithErrorLevel ¶
func WithErrorLevel() OptionFunc
WithErrorLevel only greater than 'level' will output
func WithErrorRotation ¶ added in v1.0.32
func WithErrorRotation(infoFile, errFile string, maxSize, maxBackups, maxAge int) OptionFunc
TODO
func WithFile ¶ added in v1.0.29
func WithFile(logFile string) OptionFunc
WithFile write log to some file
func WithFileRotation ¶ added in v1.0.29
func WithFileRotation(logFile string, maxSize, maxBackups, maxAge int) OptionFunc
WithFileRotation write log to some file with rotation maxSize 默认单位 M, >= 5, default 128M maxBackups, 最多保留 N 个备份, default 300 MaxAge, 最大保留时间,默认单位 day, default 30
func WithInfoLevel ¶
func WithInfoLevel() OptionFunc
WithInfoLevel only greater than 'level' will output
func WithMaxAge ¶ added in v1.0.29
func WithMaxAge(maxAge int) OptionFunc
func WithMaxBackups ¶ added in v1.0.29
func WithMaxBackups(count int) OptionFunc
WithMaxBackups 设置最大备份数
func WithMaxSize ¶ added in v1.0.29
func WithMaxSize(size int) OptionFunc
WithMaxSize 设置最大文件大小(单位: M)
func WithTimeLayout ¶
func WithTimeLayout(timeLayout string) OptionFunc
WithTimeLayout custom time format
func WithWarnLevel ¶
func WithWarnLevel() OptionFunc
WithWarnLevel only greater than 'level' will output