go-tail icon indicating copy to clipboard operation
go-tail copied to clipboard

reopen fails to reopen

Open chrisleavoy opened this issue 6 years ago • 2 comments

repro:

touch test.log
./go-tail -F ./test.log &
date > test.log
Fri Sep 15 13:26:55 EDT 2017
mv test.log test.log0 ; touch test.log
open ./test.log: no such file or directory
date >> test.log
# tail is hung/crashed, doesn't exit

Expected: no error, and date to be outputted twice.

chrisleavoy avatar Sep 15 '17 17:09 chrisleavoy

This error is related to this lines of code: https://github.com/papertrail/go-tail/blob/master/follower/follower.go#L202-L210

Basically it detects the error but it doesn't do anything about it

xocasdashdash avatar Jan 30 '19 16:01 xocasdashdash

I was able to fix this by adding a hack (sleep) after line 204:

default: if !t.config.Reopen { return nil } time.Sleep(30 * time.Second) if err := t.rewatch(); err != nil { return err }

This way if the file is moved (and then moved back) in 10s it gets reopened.

keithknott26 avatar Nov 29 '19 09:11 keithknott26