Skip to content
/ stail Public

🚀 通过系统级的命令(如`tail -f`)来循环显示文件尾部数据 | Use system-level commands (such as `tail -f`) to display tail data in a loop

License

Notifications You must be signed in to change notification settings

Licoy/stail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

中文 | English

🚀 介绍

Stail

通过系统级的命令( 如 `tail -f` )来实时监控文件变动

🔧 安装

go get github.com/Licoy/stail

🔨 使用

func useSTail(filepath string, tailLine int) {
    st, err := stail.New(stail.Options{})
    if err != nil {
        fmt.Println(err)
        return
    }
    si, err := st.Tail(filepath, tailLine, func(content string) {
        fmt.Print(fmt.Sprintf("获取到内容: %s", content))
    })
    if err != nil {
        fmt.Println(err)
        return
    }
    time.AfterFunc(time.Second*10, func() {
        err = si.Close() // 10s之后关闭获取通道
    }
    si.Watch()
}

相当于

tail -{tailLine}f {filepath}

💡 参数

  • filepath 需要监听的文件路径
  • tailLine 只查看末尾的指定行
  • call 内容回调func,内容类型为string

📝 协议

MIT

About

🚀 通过系统级的命令(如`tail -f`)来循环显示文件尾部数据 | Use system-level commands (such as `tail -f`) to display tail data in a loop

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published