Documentation
¶
Index ¶
- func Debug(args ...interface{})
- func Debugf(format string, args ...interface{})
- func DisableAutoSync()
- func DisableColor()
- func DisableSignalExitForTest()
- func EnableAutoSync()
- func EnableColor()
- func Error(args ...interface{})
- func Errorf(format string, args ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Info(args ...interface{})
- func Infof(format string, args ...interface{})
- func IsAutoSyncEnabled() bool
- func LockOutput()
- func SetLevel(level Level)
- func SetOutput(out io.Writer)
- func SimulateSignal(sig os.Signal)
- func Sync()
- func UnlockOutput()
- func Warn(args ...interface{})
- func Warnf(format string, args ...interface{})
- type Level
- type LogEntry
- func (e *LogEntry) Debug(args ...interface{})
- func (e *LogEntry) Debugf(format string, args ...interface{})
- func (e *LogEntry) Error(args ...interface{})
- func (e *LogEntry) Errorf(format string, args ...interface{})
- func (e *LogEntry) Fatal(args ...interface{})
- func (e *LogEntry) Fatalf(format string, args ...interface{})
- func (e *LogEntry) Info(args ...interface{})
- func (e *LogEntry) Infof(format string, args ...interface{})
- func (e *LogEntry) Warn(args ...interface{})
- func (e *LogEntry) Warnf(format string, args ...interface{})
- func (e *LogEntry) WithField(key string, value interface{}) *LogEntry
- func (e *LogEntry) WithFields(fields map[string]interface{}) *LogEntry
- type Logger
- func (l *Logger) Debug(args ...interface{})
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l *Logger) Error(args ...interface{})
- func (l *Logger) Errorf(format string, args ...interface{})
- func (l *Logger) Fatal(args ...interface{})
- func (l *Logger) Fatalf(format string, args ...interface{})
- func (l *Logger) Info(args ...interface{})
- func (l *Logger) Infof(format string, args ...interface{})
- func (l *Logger) SetColor(enable bool)
- func (l *Logger) Sync()
- func (l *Logger) Warn(args ...interface{})
- func (l *Logger) Warnf(format string, args ...interface{})
- func (l *Logger) WithField(key string, value interface{}) *LogEntry
- func (l *Logger) WithFields(fields map[string]interface{}) *LogEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DisableAutoSync ¶ added in v0.0.3
func DisableAutoSync()
DisableAutoSync 禁用自动同步功能。 调用后,程序退出时不会自动同步日志。 主要用于测试场景或需要完全控制同步时机的场景。
func DisableSignalExitForTest ¶ added in v0.0.3
func DisableSignalExitForTest()
DisableSignalExitForTest 禁用收到信号后的自动退出行为。 仅用于单元测试,防止测试进程被终止。
func EnableAutoSync ¶ added in v0.0.3
func EnableAutoSync()
EnableAutoSync 启用自动同步功能(默认已启用)。 程序收到 SIGINT 或 SIGTERM 信号时会自动同步日志。
func IsAutoSyncEnabled ¶ added in v0.0.3
func IsAutoSyncEnabled() bool
IsAutoSyncEnabled 返回自动同步是否启用。
func LockOutput ¶ added in v0.0.5
func LockOutput()
LockOutput 锁定日志输出,阻止日志写入直到 UnlockOutput 被调用。 主要用于需要原子输出的场景(如打印 Banner),防止日志输出打断其他输出。 注意:必须确保调用 UnlockOutput,否则日志将永久阻塞。
func SimulateSignal ¶ added in v0.0.3
SimulateSignal 模拟接收到一个信号。 这是一个辅助函数,主要用于测试目的,允许在不实际发送系统信号的情况下触发信号处理逻辑。
func Sync ¶
func Sync()
Sync 刷新默认日志记录器的日志。 注意:正常情况下无需手动调用此方法,日志库会在程序收到退出信号时自动同步。 此方法主要用于以下场景:
- 单元测试中需要立即验证日志输出
- 明确需要在某个时间点确保日志已写入
- 使用 os.Exit() 直接退出前(Fatal 系列方法已自动处理)
func UnlockOutput ¶ added in v0.0.5
func UnlockOutput()
UnlockOutput 解锁日志输出,恢复正常的日志写入。 必须与 LockOutput 配对使用。
Types ¶
type Level ¶
type Level int8
Level 定义日志级别类型。
func LevelFromString ¶
LevelFromString 辅助函数,将字符串转换为日志级别,适用于配置。
type LogEntry ¶
type LogEntry struct {
// contains filtered or unexported fields
}
LogEntry 支持链式调用的日志条目
func (*LogEntry) WithFields ¶
WithFields 添加多个字段(链式调用)
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger 保存日志记录器的配置。
func (*Logger) WithFields ¶
WithFields 创建带有预设字段的日志条目(类似logrus风格)