github地址:https://github.com/hpcloud/tail
package main
import (
"fmt"
"github.com/hpcloud/tail"
)
func main(){
config := tail.Config{
Location: &tail.SeekInfo{Offset: 0, Whence: 2}, // Seek to this location before tailing
ReOpen: true, // Reopen recreated files (tail -F)
MustExist: false, // Fail early if the file does not exist
Poll:true, // Poll for file changes instead of using inotify
Follow: true, // Continue looking for new lines (tail -f)
}
t, err := tail.TailFile("./tail.log", config)
if err != nil {
fmt.Println("open file:",err)
}
for line := range t.Lines {
fmt.Println(line.Text)
}
}