Comments (9)
Any chance of this being added? It's exactly the functionality I was looking for.
from node-tail.
I am experimenting with this package and was surprised to find that the "line" event fires for each line as expected, but it gets executed again and again for hundreds of pre-existing lines, even though I added only a single new line at the end of the file.
How can we just catch that last new line (or however many new lines have actually been added)?
from node-tail.
For what it’s worth, this package does this out of the box
from node-tail.
from node-tail.
There's no way at the moment to tail only a certain number of lines. It's either from the beginning of the file or from the latest line. I can see the need of mirroring the tail -n behaviour; the problem is that I can't see a neat way to do this with the current params list; this means I'll have to do some refactoring in the constructor signature(adding yet another params is a no, the signature is getting too long).
from node-tail.
Is this feature planned @lucagrulla?
from node-tail.
Unfortunately no.
There's no clean way to idenitfy N lines from file's tail, you can only go via trial and error (read a large of past data, count all the lines, repeat if you missed the mark).
That makes it very inefficient and error prone.
Unless something new appears in the underlying Nodejs core API I'm not looking at doing this any time soon.
from node-tail.
Here's an implementation that appears to seek character-by-character backward from the end of the file, tracking newlines, until it locates enough lines https://github.com/alexbbt/read-last-lines/blob/master/src/index.js. So, inefficient, yes, error prone, unsure. In any case this doesn't do tailing, just retrieves the last N lines, unfortunately.
What I would be most curious about would be how to merge such an implementation with tailing, making sure that while you were progressively seeking from the end of the file, you also were keeping track of new data appended to the file. I personally would take the hit on efficiency so long as the implementation was correct (in that way), because I suspect that the implementation would overall be faster and more memory-efficient for long logfiles than what I am currently doing, which is
// The 'tail' module lacks a `-n`-like option to get the last `N` lines. So what we
// do is load the entire file, but wait to render only the last `N` lines, then
// start streaming.
const N = 100;
const logs = [];
let initialDataFlushed = false;
const tail = new Tail(logfile, { fromBeginning: true });
tail
.on('line', (line) => {
if (initialDataFlushed) {
console.log(line);
} else {
logs.push(line);
if (logs.length > N) logs.shift();
}
})
.on('historicalDataEnd', () => {
logs.forEach((line) => console.log(line));
logs = [];
initialDataFlushed = true;
})
.on('error', (err) => console.error(err));
from node-tail.
Available since v.2.2.0.
from node-tail.
Related Issues (20)
- Missing lines while stream pushing too fast HOT 9
- Assess flushAtEOF flag
- From beginning option does not work in release 2.1.0 HOT 1
- Event occurs after unwatching file HOT 2
- Error README example exception £Configuration HOT 1
- Tail crashes is file is deleted HOT 1
- rename logic is incorrect on Linux
- add JSDoc and native TS support
- "Cannot use 'in' operator to search for 'follow'"
- Problem with tailing textfile in Windows HOT 3
- if nLines > count of separators, no lines are displayed
- nLines not working HOT 4
- Uncatchable error HOT 3
- Unit tests failing HOT 1
- Regex HOT 1
- Support RxJS with TypeScript check HOT 2
- delete data after read? HOT 1
- Carriage Return (\r) is messing up Mac (not tail's fault) HOT 2
- Crashes when using `nLines` with large files HOT 1
- infinite loop when tailing empty files HOT 1
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 node-tail.