在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
安装导入go get github.com/hpcloud/tail import "github.com/hpcloud/tail"
使用package main import ( "fmt" "github.com/hpcloud/tail" "time" ) func main() { filename := "E:\\project\\kafka_2.12-0.11.0.0\\config\\server.properties" //filename := ".\\my.log" tails, err := tail.TailFile(filename, tail.Config{ ReOpen: true, Follow: true, //Location: &tail.SeekInfo{Offset: 0, Whence: 2}, MustExist: false, Poll: true, }) if err != nil { fmt.Println("tail file err:", err) return } var msg *tail.Line var ok bool for true { msg, ok = <-tails.Lines if !ok { fmt.Printf("tail file close reopen, filename:%s\n", tails.Filename) time.Sleep(100 * time.Millisecond) continue } fmt.Println("msg:", msg) } }
|
请发表评论