中文 | English
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("get content: %s", content))
})
if err != nil {
fmt.Println(err)
return
}
time.AfterFunc(time.Second*10, func() {
si.Close() // close the acquisition channel after 10 s
}
si.Watch()
}
equivalent to
tail -{tailLine}f {filepath}
filepath
file path that needs to be monitoredtailLine
view only the specified line at the endcall
the content callback func, the content type is string