logger

package
v1.0.40 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDefLogDir added in v1.0.29

func GetDefLogDir(subDir string) (string, error)

func GetDefLogFile added in v1.0.29

func GetDefLogFile(subDir string, logFileName string) (string, error)

func GetLogDirFromFile added in v1.0.29

func GetLogDirFromFile(file string) string

func GetLogFileFromFile added in v1.0.29

func GetLogFileFromFile(file string, logFileName string) string

file is any file with full path format, log file will also created in the same folder

func NewDefLogger added in v1.0.29

func NewDefLogger(level types.ILogLevel, logFile string) (logger types.ILogger, err error)

NewLogger 创建新的日志器

func NewLogger

func NewLogger(options ...OptionFunc) (types.ILogger, error)

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 ILogFile added in v1.0.25

type ILogFile interface {
	io.Writer
	Close() error
}

type LogAppender

type LogAppender struct {
	Disabled bool
	Level    types.ILogLevel
	Text     bool
}

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 GetDefLogCfg(logFile string) *LogModule

func InitLogModuleCfg

func InitLogModuleCfg(baseCfg *LogModule, logModuleCfg *LogModule, moduleDefLogFile string) *LogModule

fill default data for log module, otherwise some value will be nil

func InitLogModuleCfgWithoutGlob

func InitLogModuleCfgWithoutGlob(logModuleCfg *LogModule, moduleDefLogFile string) *LogModule

type Logger added in v1.0.29

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

Logger 日志器结构

func (*Logger) Debug added in v1.0.29

func (l *Logger) Debug(args ...any)

Debug 调试日志

func (*Logger) Debugf added in v1.0.29

func (l *Logger) Debugf(format string, args ...any)

Debugf 调试日志

func (*Logger) Debugw added in v1.0.29

func (l *Logger) Debugw(msg string, keysAndValues ...any)

Debugw 调试日志, TODO

func (*Logger) Error added in v1.0.29

func (l *Logger) Error(args ...any)

Error 错误日志

func (*Logger) Errorf added in v1.0.29

func (l *Logger) Errorf(format string, args ...any)

Errorf 错误日志

func (*Logger) Errorw added in v1.0.29

func (l *Logger) Errorw(msg string, keysAndValues ...any)

Errorw 调试日志, TODO

func (*Logger) Fatal added in v1.0.29

func (l *Logger) Fatal(args ...any)

Fatal 错误日志

func (*Logger) Fatalf added in v1.0.29

func (l *Logger) Fatalf(format string, args ...any)

Fatalf 错误日志

func (*Logger) Fatalw added in v1.0.29

func (l *Logger) Fatalw(msg string, keysAndValues ...any)

Fatalw 调试日志, TODO

func (*Logger) Info added in v1.0.29

func (l *Logger) Info(args ...any)

Info 信息日志

func (*Logger) Infof added in v1.0.29

func (l *Logger) Infof(format string, args ...any)

Infof 信息日志

func (*Logger) Infow added in v1.0.29

func (l *Logger) Infow(msg string, keysAndValues ...any)

Infow 调试日志, TODO

func (*Logger) Init added in v1.0.29

func (l *Logger) Init() error

Init 初始化日志器

func (*Logger) Panic added in v1.0.29

func (l *Logger) Panic(args ...any)

Panic 错误日志

func (*Logger) Panicf added in v1.0.29

func (l *Logger) Panicf(format string, args ...any)

Panicf 错误日志

func (*Logger) Panicw added in v1.0.29

func (l *Logger) Panicw(msg string, args ...any)

Panicw 错误日志

func (*Logger) Sync added in v1.0.29

func (l *Logger) Sync() error

func (*Logger) Warn added in v1.0.29

func (l *Logger) Warn(args ...any)

Warn 错误日志

func (*Logger) Warnf added in v1.0.29

func (l *Logger) Warnf(format string, args ...any)

Warnf 信息日志

func (*Logger) Warnw added in v1.0.29

func (l *Logger) Warnw(msg string, keysAndValues ...any)

Warnw 调试日志, TODO

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 WithErrorFile added in v1.0.32

func WithErrorFile(infoFile, errFile string) OptionFunc

TODO

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 WithField

func WithField(key, value string) OptionFunc

WithField add some field(s) to log

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 WithLevel

func WithLevel(level types.ILogLevel) OptionFunc

WithLevel

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 WithNoCaller

func WithNoCaller(noCaller bool) OptionFunc

default is with caller

func WithText

func WithText(text bool) OptionFunc

default is json

func WithTimeLayout

func WithTimeLayout(timeLayout string) OptionFunc

WithTimeLayout custom time format

func WithWarnLevel

func WithWarnLevel() OptionFunc

WithWarnLevel only greater than 'level' will output

Jump to

Keyboard shortcuts

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