Closed GumpSun closed 2 years ago
What's wrong with my code???
func main() { filename := "my.log"
seek := &tail.SeekInfo{}
seek.Offset = 0
seek.Whence = os.SEEK_END
config := tail.Config{}
config.Follow = true
//config.ReOpen = true
config.Location = seek
tails, err := tail.TailFile(filename, config)
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)
}
}
When I stop using ReOpen,I got as below:
Stopping tail as file no longer exists: my.log