lucagrulla / node-tail

The zero dependency Node.js module for tailing a file
https://www.lucagrulla.com/node-tail/
MIT License
467 stars 75 forks source link

nLines not working #140

Closed wesleymv closed 2 years ago

wesleymv commented 3 years ago

I am trying to use the nLines option, but it does not seem to work. When the file is modified, it brings more than one line.

Here is the code I am using:

Tail = require('tail').Tail;

tail = new Tail("C:/Users/pc/Desktop/watchfile/1.log", {nLines: 1});

tail.on("line", function(data) {
  console.log(data);
});

tail.on("error", function(error) {
  console.log('ERROR: ', error);
});

When it starts, it brings one line. But, brings many lines when file is modified.

I am sorry if this is just the wrong use of the library.

Thank you in advance

lucagrulla commented 3 years ago

Hello @wesleymv

nLines gives you the starting point. If more lines are appended to the file, they will be then emitted.

Are the multiple lines tailed when the file changes new lines? Or are lines from the file before start tailing the file?

wesleymv commented 3 years ago

Hi @lucagrulla

The lines I get are in the old file. For example, 1.log contains:

1
2
3

when I add 4, this is the output:

31
2
3

if I remove the nLines and run the same steps (seems to omit last line):

1
2
3
lucagrulla commented 3 years ago

How are lines added?

The underline NodeJS core library is sometimes platform dependent. Are the new lines added via an app, like notepad, or with a different mechanism?

On Wed, 21 Jul 2021 at 18:45, wesleymv @.***> wrote:

Hi @lucagrulla https://github.com/lucagrulla

The lines I get are in the old file. For example, 1.log contains: 1 2 3

when I add 4, this is the output:

31 2 3

if I remove the nLines and run the same steps (seems to omit last line):

1 2 3

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/lucagrulla/node-tail/issues/140#issuecomment-884293324, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABQ6JVGZSJAXWNB2QEX2X3TY3TSFANCNFSM5AYDPYXA .

lucagrulla commented 2 years ago

Fixed with v2.2.4