File-Tail
view release on metacpan or search on metacpan
0.99 "Lyle D. Brooks" <brooks@deseret.com> reported there were instances
where interval was set to a negative value
Joe Smith <Joe.Smith@wcom.com> noted that one shouldn't declare
@ISA=qw(Autoloader) unless one is prepared to deal with it correctly.
Peter Allen <pgmppa@ibi.com> undef warnings when starting up on a
nonexistant file
Alain Fauconnet <alain@ait.ac.th> and Benjamin Zwittnig <beni@arnes.si>
provided test cases which helped me chase down another two cases where
File::Tail would spontaneously read too much.
0.99.2 Some operating systems sometimes return 0 for sysread on busy files.
This should now be handled correctly.
nowait can now be specified at object creation.
A callback is called on every file rotation, which can be used for
files that change their names with time.
0.99.3 Firefox crashed while I attempted upload to PAUSE, so I had to make
a new version just for that. Life is ridiculous.
1.0 Actually just two minor bug fixes (one of them in a test), but I no
longer see a point in not having a 1.0 version.
The File::Tail module is designed for reading files which are continously
appended to (the name comes from the tail -f directive). Usualy such files are
logfiles of some description.
The module tries hard not to busy wait on the file, dynamicaly calcultaing
how long it should wait before it pays to try reading the file again.
The module should handle normal log truncations ("close; move; open"
or "cat /dev/null >file") transparently, without losing any input.
Currently this package requires Time::HiRes, because it often needs to sleep
for less than one second. (I don't beleive one should busy wait on a file
just because it gets more than one line/second).
The file logwatch is a simple example of use. Try it with
./logwatch /var/log/syslog 1 if you want to see how File::Tail works.
This version now returns a tied filehandle, but it can also be used as
a normal object.
A feature added in 0.81 is tail -n functionality: you can demand to read the
last n lines, reading from the current end of file, or reading from the start
$crs=$object->{"buffer"}=~tr/\n//; # Count newlines in buffer
return $crs if $crs;
}
$len=$object->{"maxbuf"} if ($len>$object->{"maxbuf"});
my $nlen=$len;
while ($nlen>0) {
$len=sysread($object->{handle},$object->{"buffer"},
$nlen,length($object->{"buffer"}));
$object->{"buffer"} =~ s/\015\012/\n/g if $Is_Win32;
last if $len==0; # Some busy filesystems return 0 sometimes,
# and never give anything more from then on if
# you don't give them time to rest. This return
# allows File::Tail to use the usual exponential
# backoff.
$nlen=$nlen-$len;
}
$object->{curpos}=sysseek($object->{handle},0,SEEK_CUR);
$crs=$object->{"buffer"}=~tr/\n//;
You can find two way of using select in the file select_demo which is included
in the ditribution.
=head1 DESCRIPTION
The primary purpose of File::Tail is reading and analysing log files while
they are being written, which is especialy usefull if you are monitoring
the logging process with a tool like Tobias Oetiker's MRTG.
The module tries very hard NOT to "busy-wait" on a file that has little
traffic. Any time it reads new data from the file, it counts the number
of new lines, and divides that number by the time that passed since data
were last written to the file before that. That is considered the average
time before new data will be written. When there is no new data to read,
C<File::Tail> sleeps for that number of seconds. Thereafter, the waiting
time is recomputed dynamicaly. Note that C<File::Tail> never sleeps for
more than the number of seconds set by C<maxinterval>.
If the file does not get altered for a while, C<File::Tail> gets suspicious
and startschecking if the file was truncated, or moved and recreated. If
Tail.pm.debug view on Meta::CPAN
return $crs if $crs;
}
$len=$object->{"maxbuf"} if ($len>$object->{"maxbuf"});
logit($object,"Preparing to read in $len bytes");
my $nlen=$len;
while ($nlen>0) {
$len=sysread($object->{handle},$object->{"buffer"},
$nlen,length($object->{"buffer"}));
$object->{"buffer"} =~ s/\015\012/\n/g if $Is_Win32;
last if $len==0; # Some busy filesystems return 0 sometimes,
# and never give anything more from then on if
# you don't give them time to rest. This return
# allows File::Tail to use the usual exponential
# backoff.
$nlen=$nlen-$len;
}
$object->{curpos}=sysseek($object->{handle},0,SEEK_CUR);
$crs=$object->{"buffer"}=~tr/\n//;
$object->logit(" Got something ($len). there are now $crs newlines in buffer (".length($object->{"buffer"})." bytes)");
Tail.pm.debug view on Meta::CPAN
You can find two way of using select in the file select_demo which is included
in the ditribution.
=head1 DESCRIPTION
The primary purpose of File::Tail is reading and analysing log files while
they are being written, which is especialy usefull if you are monitoring
the logging process with a tool like Tobias Oetiker's MRTG.
The module tries very hard NOT to "busy-wait" on a file that has little
traffic. Any time it reads new data from the file, it counts the number
of new lines, and divides that number by the time that passed since data
were last written to the file before that. That is considered the average
time before new data will be written. When there is no new data to read,
C<File::Tail> sleeps for that number of seconds. Thereafter, the waiting
time is recomputed dynamicaly. Note that C<File::Tail> never sleeps for
more than the number of seconds set by C<maxinterval>.
If the file does not get altered for a while, C<File::Tail> gets suspicious
and startschecking if the file was truncated, or moved and recreated. If
( run in 0.468 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )