I am facing a bizarre behaviour from Wheel::FollowTail.
Basically, sometimes it detects the log reset, sometimes it doesn't.
Sometimes it gets the record, sometimes it doesn't. From my extensive
tests, it seems to work only in 10% of the cases.
The file watched is overwritten by an application every 10-15 minutes,
contains only 3 lines. Here is an example of its contents:
namp@tewap4 ~/code> cat /namp_log/log/TRLOGStatus.cfg
#
#Sun Sep 14 18:03:05 IRDT 2008
TRFILE_INDEX_NUMBER=157
The file is on a normal filesystem:
/namp_log on /dev/md/dsk/d50
read/write/setuid/devices/intr/largefiles/logging/xattr/noatime/onerror=panic/dev=1540032
on Tue Sep 9 00:58:53 2008
Any idea what could cause this?
O/S is Solaris, Perl 5.10 built from source using gcc, latest version of POE.
I'm about to revert to a more 'tradition' approach of watching the
file (e.g. checking its timestamp every minute) but I wouldn't mind
figuring out why FollowTail, which has worked perfectly fine on other
projects, behaves this way on this file.
Here is the simple code I am using.
sub InitWapLog
# Define POE records
{
$poe_records{_start} = \&begin_watchers;
$poe_records{index_record} = \&index_got_record;
$poe_records{index_log_reset} = \&index_log_reset;
$poe_records{log_error} = \&generic_log_error;
&Log("Init complete");
}
sub begin_watchers
# Start POE sessions
{
my $heap = $_[HEAP];
my $logid;
my $log_watcher = POE::Wheel::FollowTail->new
(
Filename => $LogStatus,
InputEvent => "index_record",
ResetEvent => "index_log_reset",
ErrorEvent => "log_error",
);
$heap->{services}->{ $log_watcher->ID } = "index";
$heap->{watchers}->{ $log_watcher->ID } = $log_watcher;
&Log("Started watch on file $LogStatus");
}
sub index_got_record
# Handle index file reset
{
my ($record, $wheel_id, $heap) = @_[ARG0, ARG1, HEAP];
my $service = $heap->{services}->{$wheel_id};
&Log("index: read $record");
}
sub index_log_reset
# An index log reset means the current log has been closed
{
my ($heap, $wheel_id) = @_[HEAP, ARG0];
my $service = $heap->{services}->{$wheel_id};
&Log("$service log reset");
}
sub generic_log_error
# Handles log errors
{
my ($heap, $operation, $errno, $error_string, $wheel_id) = @_[
HEAP, ARG0, ARG1, ARG2, ARG3 ];
my $service = $heap->{services}->{$wheel_id};
&Log("$service log $operation error $errno: $error_string\n");
&Log("Shutting down $service log watcher.\n");
delete $heap->{services}->{$wheel_id};
delete $heap->{watchers}->{$wheel_id};
}
# MAIN
my $LogStatus = "/namp_log/log/TRLOGStatus.cfg";
&Log("Starting WAP log watch");
&InitWapLog;
POE::Session->create(inline_states => {%poe_records});
$poe_kernel->run();
&Log("All watchers died, exiting");
exit;
Emmanuel> The file watched is overwritten by an application every 10-15 minutes,
Emmanuel> contains only 3 lines. Here is an example of its contents:
By overwritten, what do you mean?
If the file is rewound and rewritten in place, that's not the kind of thing
that tail -f or FollowTail can detect (and is generally bad practice). If the
file is unlinked (or renamed) and a new file put in its place, FollowTail
*should* detect that.
Check the inode number on each rewrite (ls -i). If the number doesn't
change, FollowTail isn't misbehaving -- the application is. :)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<mer...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
> Check the inode number on each rewrite (ls -i). If the number doesn't
> change, FollowTail isn't misbehaving -- the application is. :)
Good point. Actually, the inode doesn't change.
So this would mean I can't use FollowTail then.
Thanks