remLog

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

全局日志方法 - 支持多参数

func Debugf

func Debugf(format string, args ...interface{})

全局日志方法 - 支持格式化

func DisableAutoSync added in v0.0.3

func DisableAutoSync()

DisableAutoSync 禁用自动同步功能。 调用后,程序退出时不会自动同步日志。 主要用于测试场景或需要完全控制同步时机的场景。

func DisableColor added in v0.0.3

func DisableColor()

DisableColor 禁用默认日志记录器的颜色输出。

func DisableSignalExitForTest added in v0.0.3

func DisableSignalExitForTest()

DisableSignalExitForTest 禁用收到信号后的自动退出行为。 仅用于单元测试,防止测试进程被终止。

func EnableAutoSync added in v0.0.3

func EnableAutoSync()

EnableAutoSync 启用自动同步功能(默认已启用)。 程序收到 SIGINT 或 SIGTERM 信号时会自动同步日志。

func EnableColor added in v0.0.3

func EnableColor()

EnableColor 启用默认日志记录器的颜色输出。

func Error

func Error(args ...interface{})

func Errorf

func Errorf(format string, args ...interface{})

func Fatal

func Fatal(args ...interface{})

func Fatalf

func Fatalf(format string, args ...interface{})

func Info

func Info(args ...interface{})

func Infof

func Infof(format string, args ...interface{})

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 SetLevel

func SetLevel(level Level)

SetLevel 设置默认日志记录器的日志级别。

func SetOutput

func SetOutput(out io.Writer)

SetOutput 设置默认日志记录器的输出目标。

func SimulateSignal added in v0.0.3

func SimulateSignal(sig os.Signal)

SimulateSignal 模拟接收到一个信号。 这是一个辅助函数,主要用于测试目的,允许在不实际发送系统信号的情况下触发信号处理逻辑。

func Sync

func Sync()

Sync 刷新默认日志记录器的日志。 注意:正常情况下无需手动调用此方法,日志库会在程序收到退出信号时自动同步。 此方法主要用于以下场景:

  • 单元测试中需要立即验证日志输出
  • 明确需要在某个时间点确保日志已写入
  • 使用 os.Exit() 直接退出前(Fatal 系列方法已自动处理)

func UnlockOutput added in v0.0.5

func UnlockOutput()

UnlockOutput 解锁日志输出,恢复正常的日志写入。 必须与 LockOutput 配对使用。

func Warn

func Warn(args ...interface{})

func Warnf

func Warnf(format string, args ...interface{})

Types

type Level

type Level int8

Level 定义日志级别类型。

const (
	// DEBUG 级别:通常仅在调试时启用,日志非常详细。
	DEBUG Level = iota - 1
	// INFO 级别:关于应用程序内部操作的常规条目。
	INFO
	// WARN 级别:非关键性条目,但值得关注。
	WARN
	// ERROR 级别:需要立即处理的日志。
	ERROR
	// FATAL 级别:严重错误,可能会导致应用程序终止。
	FATAL
)

func LevelFromString

func LevelFromString(levelStr string) (Level, error)

LevelFromString 辅助函数,将字符串转换为日志级别,适用于配置。

func (Level) String

func (l Level) String() string

String 返回日志级别的字符串表示。

type LogEntry

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

LogEntry 支持链式调用的日志条目

func WithField

func WithField(key string, value interface{}) *LogEntry

func WithFields

func WithFields(fields map[string]interface{}) *LogEntry

全局WithFields方法

func (*LogEntry) Debug

func (e *LogEntry) Debug(args ...interface{})

func (*LogEntry) Debugf

func (e *LogEntry) Debugf(format string, args ...interface{})

func (*LogEntry) Error

func (e *LogEntry) Error(args ...interface{})

func (*LogEntry) Errorf

func (e *LogEntry) Errorf(format string, args ...interface{})

func (*LogEntry) Fatal

func (e *LogEntry) Fatal(args ...interface{})

func (*LogEntry) Fatalf

func (e *LogEntry) Fatalf(format string, args ...interface{})

func (*LogEntry) Info

func (e *LogEntry) Info(args ...interface{})

func (*LogEntry) Infof

func (e *LogEntry) Infof(format string, args ...interface{})

func (*LogEntry) Warn

func (e *LogEntry) Warn(args ...interface{})

func (*LogEntry) Warnf

func (e *LogEntry) Warnf(format string, args ...interface{})

func (*LogEntry) WithField

func (e *LogEntry) WithField(key string, value interface{}) *LogEntry

WithField 添加字段(链式调用)

func (*LogEntry) WithFields

func (e *LogEntry) WithFields(fields map[string]interface{}) *LogEntry

WithFields 添加多个字段(链式调用)

type Logger

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

Logger 保存日志记录器的配置。

func New

func New(out io.Writer, level Level) *Logger

New 创建一个新的 Logger 实例。

func (*Logger) Debug

func (l *Logger) Debug(args ...interface{})

Logger 实例的公共日志方法 - 支持多参数

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...interface{})

Logger 实例的公共日志方法 - 支持格式化

func (*Logger) Error

func (l *Logger) Error(args ...interface{})

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(args ...interface{})

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...interface{})

func (*Logger) Info

func (l *Logger) Info(args ...interface{})

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...interface{})

func (*Logger) SetColor added in v0.0.3

func (l *Logger) SetColor(enable bool)

SetColor 设置是否启用颜色输出。

func (*Logger) Sync

func (l *Logger) Sync()

Sync 刷新所有缓冲的日志到输出。 应在应用程序退出之前调用。

func (*Logger) Warn

func (l *Logger) Warn(args ...interface{})

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...interface{})

func (*Logger) WithField

func (l *Logger) WithField(key string, value interface{}) *LogEntry

WithField 创建带有单个预设字段的日志条目

func (*Logger) WithFields

func (l *Logger) WithFields(fields map[string]interface{}) *LogEntry

WithFields 创建带有预设字段的日志条目(类似logrus风格)

Jump to

Keyboard shortcuts

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