Search code examples
node.jstail

Node.js Library to start tailing a file from specific line or line number?


I am searching for library/module that starts tailing from a specific line number so that even if my server dies down or restarts it should start from the last read line. I am little new to node.js


Solution

  • This is how I tackled the problem.
    I maintained two log files one of which use to store the lines already read so even if my server dies down reading the main log file I can skip all the logs I have already logged by comparing the time of last logged line with the time of the main log and skip the lines of main log till the time of my own log is greater than or equal to the main log.
    Once the mainlog time is greater I start reading the from that point again.