in reply to Log file tailing

I use a different approach than IO::Select when solving this type of problem. Operating systems maintain an end of file marker, which determines how much of the file is readable by another process - the size of the file in bytes.

My approach is as follows (pseudocode):

while (1) { stat the file if size of file changed since last time { open file seek to previous EOF print file contents until EOF save EOF position for next time close the file } sleep for x seconds }
Hope this helps

--
I'm Not Just Another Perl Hacker

Replies are listed 'Best First'.
Re: Re: Log file tailing
by matija (Priest) on May 18, 2004 at 05:28 UTC
    Well, that is essentialy what File::Tail does. Except that File::Tail also adjusts the "sleep for x seconds" duration after every read to account for how "busy" the file is: it checks the more frequently updated files more often, and the less frequently updated files less often.

    It also checks for files that have suddenly become shorter (as when a sysadmin does a cat /dev/null >logfile in order to free space), and if the file has not been written for a long time, it closes and reopens it - thus hopefully catching cases where the file has been renamed during a log rotation.