Comments (3)
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.
t, err := tail.TailFile(catalinaPath,
tail.Config{
Follow: true,
CompleteLines: true,
Location: &tail.SeekInfo{Offset: 0, Whence: io.SeekEnd},
})
from tail.
I also found this workaround:
for line := range tailfile.Lines {
pos, _ := tailfile.Tell()
if pos != line.SeekInfo.Offset {
continue
}
sendNewLogLine(line.Text)
}
It works a little, however the last line in a truncated file is always send this eample.
from tail.
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
Test it locally and it works really nice.
from tail.
Related Issues (20)
- [Question] The line will be truncated during kube-apiserver (another app) is writing in. HOT 2
- Cannot determine if a given line is complete or not HOT 17
- End log lost due to log rotation HOT 1
- Inotify backend does not correctly handle one file being watched twice HOT 2
- StopAtEOF does not function as expected. HOT 2
- Concurrent usage of tail results in unexpected behavior HOT 1
- Tail non-existent file: Lines channel closes when MustExist=false. HOT 3
- StartTail followed by append to file is race-prone
- package not in GOROOT HOT 1
- inotify_tracker logs fatal message without including error
- The message in the chan is incomplete. HOT 2
- File unexpectedly closes during tailing process
- Continious truncate is not handled correctly HOT 1
- read part message HOT 1
- Support `tail -n`
- StopAtEOF is racy
- Add error message to logs
- Log collection row loss and duplication
- log rotate loss log, tail not stop or kill, why deleted signal lost[hpcloud/tail v1.0.0]
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tail.