Licoy / stail

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

中文 | 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

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

License:MIT License


Languages

Language:Go 97.9%Language:Batchfile 2.1%