Documentation
¶
Index ¶
- func CleanFiles(pattern string, remaining int) error
- func Exists(name string) (bool, error)
- func KeepDirExists(dir string) error
- func RotateRuleNames() []string
- func SetRotateRule(rules ...*RotateRule) error
- type HasFd
- type Keeper
- type RotateRule
- type Rotator
- type WatchFile
- type Watcher
- type WatcherEvent
- type WatcherEventType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanFiles ¶
CleanFiles 按照文件前缀清理文件
pattern: eg /home/work/logs/access_log.log.* remaining: 文件保留个数,eq :24
func KeepDirExists ¶
KeepDirExists 保持文件夹存在,若不存在则创建 若路径为文件,则删除,然后创建文件夹
func RotateRuleNames ¶ added in v0.0.5
func RotateRuleNames() []string
RotateRuleNames 返回所有切割规则的名称,已按照切割间隔升序排列
func SetRotateRule ¶ added in v0.0.5
func SetRotateRule(rules ...*RotateRule) error
SetRotateRule 设置新的切割规则,若和原有的重复,会覆盖掉
Types ¶
type Keeper ¶
type Keeper struct { // FilePath 返回文件地址,必填 FilePath func() string // OpenFile 创建文件的函数,可选 // 默认为 os.OpenFile(fp, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644) OpenFile func(fp string) (*os.File, error) // CheckInterval 检查间隔,可选 // 默认为 100ms CheckInterval time.Duration // contains filtered or unexported fields }
Keeper 保持文件存在
func (*Keeper) AfterChange ¶
AfterChange 注册当文件变化后的回调函数
func (*Keeper) BeforeChange ¶
BeforeChange 注册当文件变化前的回调函数
type RotateRule ¶ added in v0.0.5
RotateRule 切割规则
type Rotator ¶
type Rotator struct { // ExtFunc 文件后缀生成的自定义函数,可选 // 优先使用 ExtRule ExtFunc func() string // NewWriter 对文件的封装 NewWriter func(w io.Writer) fsio.ResetWriter // ExtRule 文件后缀生成的规则,可选 // 目前支持:1hour、1day、no(默认) ExtRule string // Path 文件名 Path string // MaxFiles 最多保留文件数,超过的文件将被清理掉,默认值为 24 // 若值为 -1,则保留所有文件 MaxFiles int // MaxDelay 最大延迟时间,可选,默认为 100ms. // 影响文件状态、buffer. // 如文件被删除了,则最大间隔 MaxDelay 时长会检查到 MaxDelay time.Duration // contains filtered or unexported fields }
Rotator 文件具备自动切割的功能
func (*Rotator) AfterChange ¶
AfterChange 注册当文件变化时的回调函数
type WatchFile ¶
type WatchFile struct { FileName string Parser func(content []byte) error // contains filtered or unexported fields }
WatchFile watch file
func (*WatchFile) OnFileChange ¶
func (wf *WatchFile) OnFileChange(fn func())
OnFileChange register file change callback
type Watcher ¶
type Watcher struct { Interval time.Duration Delay time.Duration // contains filtered or unexported fields }
Watcher 文件监听
func (*Watcher) Watch ¶
func (w *Watcher) Watch(name string, callback func(event WatcherEvent))
Watch add file watch with callback
type WatcherEvent ¶
type WatcherEvent struct { FileName string Type WatcherEventType }
WatcherEvent event for watcher
type WatcherEventType ¶ added in v0.0.6
type WatcherEventType string
const ( // WatcherEventUpdate contains create and update ent WatcherEventUpdate WatcherEventType = "update" // WatcherEventDelete delete event WatcherEventDelete WatcherEventType = "delete" )
Click to show internal directories.
Click to hide internal directories.