OK, this may seem like an easy question, but I could not find the answer from here, so I am posting it in the hope that someone has encountered a similar problem.
I need to track a symbolic link that points to a web server file ( /var/log/lighttpd/error.log , more specifically, thanks to Linus G Thiel I figured out how to follow symbolic links ). I know that I can configure fs.fileWatch to monitor it, but I must also indicate that the error.log file was also rotated at a specific time, depending on what parameters of the log daemon. When this happens, fs.fileWatch stops working. I also know that I can spawn a child process and run
tail -F ./symlink_to_error.log
from node to get around the issue caused by log rotation, but I prefer to use node's own functions. Can anyone shed some light on this?
[EDIT]
In fact, monitoring the actual log file works without problems, even when the log file is rotated. The problem is actually caused by a symbolic link. The reason I control the symlink is because the log file name changes when the size reaches a certain limit. /var/log/lighttpd/error.log is an example only. I cannot control how the log file is renamed, but I have a crontab that updates a symlink every minute, which updates a symlink.
[EDIT 2/28/2012]
I actually use the following method (via spawn)
tail -F ./symlink_to_error.log
in the log monitoring project I'm working on, since it works pretty reliably, although it's not as efficient as watchFile ().
source share