Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tail.Config ReOpen abnormal #176

Closed
GumpSun opened this issue Oct 14, 2020 · 1 comment
Closed

tail.Config ReOpen abnormal #176

GumpSun opened this issue Oct 14, 2020 · 1 comment

Comments

@GumpSun
Copy link

GumpSun commented Oct 14, 2020

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)

When I stop using ReOpen,I got as below:

Stopping tail as file no longer exists: my.log

@GumpSun
Copy link
Author

GumpSun commented Oct 14, 2020

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)
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant