support Follow=false
This commit is contained in:
parent
92ad722d56
commit
f461ddc97d
|
@ -5,6 +5,7 @@
|
||||||
* Fix potential race condition when reopening the file (issue 5)
|
* Fix potential race condition when reopening the file (issue 5)
|
||||||
* Fix potential blocking of `tail.Stop` (issue 4)
|
* Fix potential blocking of `tail.Stop` (issue 4)
|
||||||
* Fix uncleaned up ChangeEvents goroutines after calling tail.Stop
|
* Fix uncleaned up ChangeEvents goroutines after calling tail.Stop
|
||||||
|
* Support Follow=false
|
||||||
|
|
||||||
# Feb, 2013
|
# Feb, 2013
|
||||||
|
|
||||||
|
|
7
tail.go
7
tail.go
|
@ -58,10 +58,6 @@ func TailFile(filename string, config Config) (*Tail, error) {
|
||||||
panic("cannot set ReOpen without Follow.")
|
panic("cannot set ReOpen without Follow.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !config.Follow {
|
|
||||||
panic("Follow=false is not supported.")
|
|
||||||
}
|
|
||||||
|
|
||||||
t := &Tail{
|
t := &Tail{
|
||||||
Filename: filename,
|
Filename: filename,
|
||||||
Lines: make(chan *Line),
|
Lines: make(chan *Line),
|
||||||
|
@ -160,6 +156,9 @@ func (tail *Tail) tailFileSync() {
|
||||||
tail.sendLine(line)
|
tail.sendLine(line)
|
||||||
}
|
}
|
||||||
case io.EOF:
|
case io.EOF:
|
||||||
|
if !tail.Follow {
|
||||||
|
return
|
||||||
|
}
|
||||||
// When EOF is reached, wait for more data to become
|
// When EOF is reached, wait for more data to become
|
||||||
// available. Wait strategy is based on the `tail.watcher`
|
// available. Wait strategy is based on the `tail.watcher`
|
||||||
// implementation (inotify or polling).
|
// implementation (inotify or polling).
|
||||||
|
|
14
tail_test.go
14
tail_test.go
|
@ -66,6 +66,20 @@ func TestLocationFull(_t *testing.T) {
|
||||||
tail.Stop()
|
tail.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLocationFullDontFollow(_t *testing.T) {
|
||||||
|
t := NewTailTest("location-full-dontfollow", _t)
|
||||||
|
t.CreateFile("test.txt", "hello\nworld\n")
|
||||||
|
tail := t.StartTail("test.txt", Config{Follow: false, Location: -1})
|
||||||
|
go t.VerifyTailOutput(tail, []string{"hello", "world"})
|
||||||
|
|
||||||
|
// Add more data only after reasonable delay.
|
||||||
|
<-time.After(100 * time.Millisecond)
|
||||||
|
t.AppendFile("test.txt", "more\ndata\n")
|
||||||
|
<-time.After(100 * time.Millisecond)
|
||||||
|
|
||||||
|
tail.Stop()
|
||||||
|
}
|
||||||
|
|
||||||
func TestLocationEnd(_t *testing.T) {
|
func TestLocationEnd(_t *testing.T) {
|
||||||
t := NewTailTest("location-end", _t)
|
t := NewTailTest("location-end", _t)
|
||||||
t.CreateFile("test.txt", "hello\nworld\n")
|
t.CreateFile("test.txt", "hello\nworld\n")
|
||||||
|
|
Loading…
Reference in New Issue