Tails a file. it should work great. it will continue to work even if a file is unlinked rotated or truncated. It is also ok if the path doesnt exist before watching it
var tail = require('tailfd').tail,
watcher = tail('/some.log',function(line,tailInfo){
//default line listener. optional.
console.log('line of data> ',line);
});
when you are done
watcher.close();
npm install tailfd
tailfd.tail(filename, [options], listener)
filename
options. supported custom options are
{
"start":undefined, //defaults to the first reported stat.size
//optional. a hard start position in the file for tail to start emitting data events.
"offset":0,
//optional. offset is negtively applied to the start position
"delimiter":"\n",
//optional. defaults to newline but can be anything
"maxBytesPerRead":10240,
// optional. this is how much data will be read off of a file descriptor in one call to fs.read. defaults to 10k.
// the maximum data buffer size for each tail is
// maxBufferPerRead + the last incomplete line from the previous read.length
"readAttempts":3,
//optional. if fs.read cannot read the offset from a file it will try attempts times before is gives up with a range-unreadable event
// defaults to 3 attempts
"maxLineLength":102400
// optional. defaults to 1 mb
// if the line excedes this length it's data will be emitted as a line-part event
// this is a failsafe so that a single line cant eat all of the memory.
// all gathered line-parts are complete with the value of the next line event for that file descriptor.
}
// the options object is passed to watchfd as well. With watchfd you may configure
{
"timeout": 60*60*1000, //defaults to one hour
//how long an inactive file descriptor can remain inactive before being cleared
"timeoutInterval":60*5*1000 //every five minutes
// how often to check for inactive file descriptors
}
//the options object is also passed directly to fs.watch and fs.watchFile so you may configure
{
"persistent":true, //defaults to true
//persistent indicates whether the process should continue to run as long as files are being watched
"interval":0, //defaults 0
//interval indicates how often the target should be polled, in milliseconds. (On Linux systems with inotify, interval is ignored.)
}
callback
callback(line,tailInfo)
cur and prev are instances of fs.Stats
@returns TailFD Watcher
Watcher.pause
Watcher.resume