Comments (7)
Figured this out by myself. Just had to specify a SeekInfo in the tail config object:
tail, err := tail.TailFile("testFile.txt", tail.Config{
Location: &tail.SeekInfo{
Whence: io.SeekEnd,
},
// Rest of config
})
from tail.
Thank you for responding, I have tried the same, but every time I save the file with a new line, I receive all lines from start. Instead, I want only new lines
Just gonna report my experience here because I thought I was facing the same issue as you, and it turns out that's not the case.
The library works as expected, and does not resend every line from the start if you append new lines correctly. By this I mean that you actually append new lines. What some editors do is that, when you write a new line to the end of a file and save it, the editor then opens the file in write mode and rewrites all contents to it, instead of just appending to the end. This makes tail
see the file changed as a whole and so it resends all lines from the start.
If you actually use an append mode to write to the file, you will see it behave exactly as you want it to. One way to test this is to append with echo
, like so echo "line content" >> /path/to/file
(notice the use of >>
there, not >
)
from tail.
Than you for the digging (and excuses for my late reaction). Do you see a place where we could inprove the documentation? I am trying to cleanup and test the noTomb branch where the API and doc should be improved (https://github.com/nxadm/tail/tree/noTomb).
from tail.
No worries! Looking further into it, this is a gripe I have with Go's io
package, where the Seek function lives. They use the word 'whence,' which is absolutely meaningless, but it is well-commented. So, short of having a Github wiki page or something, I'm not really sure there's actually anything you can do here. :/
from tail.
Hi Team,
This library by default returns every line again from the start if follow is enabled. how to receive only new lines? I am trying to understand but could not figure it out. Can you help me
from tail.
When I used this, I seeked to the end:
w.tail, tailErr = tail.TailFile(path, tail.Config{
Location: &tail.SeekInfo{
Whence: io.SeekEnd,
},
ReOpen: true,
Follow: true,
})
I don't know how valid this is still, since it's been years.
from tail.
Thank you for responding,
I have tried the same, but every time I save the file with a new line, I receive all lines from start. Instead, I want only new lines
from tail.
Related Issues (20)
- noTomb: useless fmt.Errorf calls HOT 3
- Don't tail for repeatedly opened file. HOT 5
- Dealing with utf16 string HOT 2
- [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
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.