You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an issue with Tail. We have an application that watches a file to send changes to an event bus to generate alerts.
The issue is that when the file is truncated and reopened it re-reads the file. The problem is that in our case also all the lines are send to the event bus again. I was digging in to the docs but I could not find a ways to prevent this.
So is there an option in Tail to go to directly to the end of a file without fully reading it when a file is reopened after a truncate?
The text was updated successfully, but these errors were encountered:
ouwe-knutselaar
changed the title
Getting a signal when a file is reopenen
Prevent a full file read when a file is reopened after truncation
Aug 28, 2024
Hey, just had the same issue but I think I managed to resolve it.
Have you tried setting the Location when creating the Tail with config?
This is my conf and it doesn't read the file from the start. I only want to listen for the new logs.
What also Could be done is to add an extra field in the config struct: ToEndAfterTruncate bool // Go to the end of a file after a truncation to prevent double file read
And then add this piece of code to the function waitForChanges()
case <-tail.changes.Truncated:
// Always reopen truncated files (Follow is true)
tail.Logger.Printf("Re-opening truncated file %s ...", tail.Filename)
if err := tail.reopen(); err != nil {
return err
}
tail.Logger.Printf("Successfully reopened truncated %s", tail.Filename)
tail.openReader()
// New snippet
if tail.ToEndAfterTruncate {
tail.Logger.Printf("Jump to the end of the file after being truncated %s", tail.Filename)
if err := tail.seekEnd(); err != nil {
return err
}
}
// End
return nil
L.S.
I have an issue with Tail. We have an application that watches a file to send changes to an event bus to generate alerts.
The issue is that when the file is truncated and reopened it re-reads the file. The problem is that in our case also all the lines are send to the event bus again. I was digging in to the docs but I could not find a ways to prevent this.
So is there an option in Tail to go to directly to the end of a file without fully reading it when a file is reopened after a truncate?
The text was updated successfully, but these errors were encountered: