I'm trying to watch log rotated files with node.js and parse each line for keywords. The Problem is: after logrotate I'm still watching the old file because of the opened file discriptor.
I'm new to this and have two questions:
- Is it advisable to check after every line the inode and if it's not the same close the fd and read the file 'filename' again?
- What's the best way achieving this? Trying to avoid callbacks and use events instead or is there an library already?
Thanks!
When the log file is rotated, it is being renamed.
The fs.watch function in node.js has the ability to notify you when the file changes.
http://www.nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener