Documentation
¶
Index ¶
- func Alert(format string, v ...any)
- func Critical(format string, v ...any)
- func Debug(format string, v ...any)
- func Emergency(format string, v ...any)
- func Error(format string, v ...any)
- func Fatal(format string, v ...any)
- func Info(format string, v ...any)
- func Notice(format string, v ...any)
- func Panic(format string, v ...any)
- func SetExitLevel(levels []Level)
- func SetFormatFunc(format FormatFunc)
- func SetLevel(level Level)
- func SetPrefix(prefix string)
- func SetWriter(w io.Writer)
- func Trace(format string, v ...any)
- func Warn(format string, v ...any)
- func Warning(format string, v ...any)
- type FormatFunc
- type Level
- type LogEntry
- type Logger
- func (l *Logger) Alert(format string, v ...any)
- func (l *Logger) Critical(format string, v ...any)
- func (l *Logger) Debug(format string, v ...any)
- func (l *Logger) Emergency(format string, v ...any)
- func (l *Logger) Error(format string, v ...any)
- func (l *Logger) Fatal(format string, v ...any)
- func (l *Logger) Info(format string, v ...any)
- func (l *Logger) Notice(format string, v ...any)
- func (l *Logger) Panic(format string, v ...any)
- func (l *Logger) SetExitLevel(levels []Level)
- func (l *Logger) SetFormatFunc(format FormatFunc)
- func (l *Logger) SetLevel(level Level)
- func (l *Logger) SetPrefix(p string)
- func (l *Logger) SetWriter(w io.Writer)
- func (l *Logger) Trace(format string, v ...any)
- func (l *Logger) Warn(format string, v ...any)
- func (l *Logger) Warning(format string, v ...any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetExitLevel ¶ added in v0.1.4
func SetExitLevel(levels []Level)
SetExitLevel 设置全局日志退出等级 当日志等级匹配时会触发 os.Exit(1)
func SetFormatFunc ¶ added in v0.1.4
func SetFormatFunc(format FormatFunc)
SetFormatFunc 设置全局日志格式化函数
Types ¶
type FormatFunc ¶ added in v0.1.4
FormatFunc 格式化函数类型 输入: 日志条目 输出: 格式化后的日志字符串
type Level ¶
type Level int
type LogEntry ¶ added in v0.1.4
type LogEntry struct { Time time.Time // 日志生成的时间点 Level Level // 实际日志等级(如 TRACE、INFO、ERROR 等) SetLevel Level // 配置或设置的日志等级,用于过滤输出 Prefix string // 日志前缀,可用于标识模块或子系统,可为空 CallDepth int // 调用堆栈深度,用于定位日志来源(文件和行号) File string // 日志来源文件路径,可为相对路径或经过格式化的路径 Line int // 日志来源行号 Message string // 日志正文内容 }
LogEntry 日志条目结构体
type Logger ¶
type Logger struct { CallDepth int // 用于 runtime.Caller 输出调用堆栈深度 // contains filtered or unexported fields }
Logger 日志结构体 - 支持多等级日志 - 并发安全 - 支持彩色输出 - 可自定义日志格式
func (*Logger) SetExitLevel ¶
SetExitLevel 设置日志等级触发 os.Exit(线程安全)
func (*Logger) SetFormatFunc ¶ added in v0.1.4
func (l *Logger) SetFormatFunc(format FormatFunc)
SetFormatFunc 设置日志格式化函数(线程安全)
func (*Logger) SetPrefix ¶ added in v0.1.4
SetPrefix 设置日志前缀(线程安全)
func (*Logger) SetWriter ¶ added in v0.1.4
SetWriter 设置日志输出 io.Writer
Source Files
¶
- format.go
- level.go
- log.go
- logger.go
Click to show internal directories.
Click to hide internal directories.