[RFC] File::Rotate - read from rotating logfiles

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!


I've written a module which might be useful by others. Comments and a
better name are welcome.


       File::Rotate - read from rotating logfiles

         use File::Rotate;
         my $fh = new File::Rotate(file      => $file,
                                   statefile => $statefile);
         die unless($fh);

         while (my $line = $fh->getline) {
             # do something with $line

       File::Rotate allows you to easily read from files such as those
       produced by syslog(8) without the hassle of worrying about file
       rotation or compression. File rotation is automatically
       detected. This module would typically be used by programs
       called at regular intervals from cron(8).

       new( file => $file, statefile => $statefile)

       Creates a "File::Rotate" object representing the file $file
       initialised with the state stored in $statefile. If $statefile
       does not exist it will be created and the file pointer will be
       set to zero (start of $file). If $statefile is a valid
       statefile for $file the file pointer will be moved to the last
       read position (in either $file or a rotated and/or compressed

       $fh->getline( )

       Will return the next string from $file, or from the rotated
       version of $file. When the end of the rotated file is reached
       lines will be returned from the current $file. When the last
       file is reached 'undef' will be returned.

       $fh->save_state( )

       Save the current file pointer position to $statefile.


Site Timeline