advice for tailing a file
Vikas N Kumar
vikas at vikaskumar.org
Tue Dec 15 00:17:04 CET 2015
On 12/14/2015 05:58 PM, Scott Wiersdorf wrote:
> Back to my original question: how? I don't know how to get a "file
> append" event in an OS-agnostic way. Do you?
If you're not planning to run on Windows, then you can just use the
"tail -F" command on the log file and pass that as a file handle to
open() and then that file handle can be read using AnyEvent. Then any
appends, or truncation or overwrites of the file can be handled by the
"tail" command and you just are reading its output.
All Unix-clones have a tail command.
I don't think there is anything such as a "file append" event in an OS.
Each OS may have its own version of inotify(), and I am not aware if
that is abstracted out in a single perl module.
Look at https://github.com/sschober/kqwait to see how kqueue() is used
on BSD/Mac to do the inotify() like call as in Linux.
You can also do a file read event and if EOF is seen, then check the
file size to see if it has been closed or if any appending has happened.
But that is what File::Tail already does.
More information about the anyevent
mailing list