Documentation
¶
Overview ¶
Package filerotate 提供多进程安全的文件轮转功能。
本文件实现 Unix 平台的文件打开。
Package filerotate 提供多进程安全的文件轮转功能。
本文件包含文件轮转的核心操作:重命名、创建新文件、清理过期备份。
Package filerotate 提供多进程安全的文件轮转功能。
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrFileNotOpen = errors.New("filerotate: file not open")
ErrFileNotOpen 表示文件未打开时尝试写入。
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
FilePath string // 文件路径,所有并发进程必须相同
MaxSizeMB int // 触发轮转的文件大小(MB),0 表示永不轮转
MaxAgeDays int // 备份文件保留天数,0 表示永不删除
CheckInterval time.Duration // 文件检查间隔,默认 1s
ErrorHandler func(error) // 内部 goroutine 错误回调,默认打印 stderr
}
Config Writer 配置。
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer 是多进程安全的文件写入器。
通过内置 polling goroutine 定期检查文件状态(大小 + inode), 超阈值时通过文件锁竞争轮转权。Write() 热路径不加锁, 依赖 O_APPEND 内核级原子追加。支持本地文件系统和 NFS。
Click to show internal directories.
Click to hide internal directories.