in reply to Adding flexibility to Watching_Logs example in POE Cookbook
There may be other ways, here is mine (unified diff, you need to patch your program):
--- 504441.pl 2005-11-01 10:19:54.000000000 +0200 +++ 504441.pl-new 2005-11-01 10:19:36.000000000 +0200 @@ -64,11 +64,25 @@ # Handle log resets and errors the same way for each file.^M log_reset => \&generic_log_reset,^M log_error => \&generic_log_error,^M + alarm_reset => \&alarm_reset,^M }^M );^M ^M +sub alarm_reset{^M + print "ALARM!\n";^M + my ($kernel, $heap) = @_[KERNEL, HEAP];^M + if ( exists( $heap->{'alarm'} ) ){^M + delete $heap->{'services'};^M + delete $heap->{'watchers'};^M + $kernel->delay_add( "alarm_reset", 10 );^M + $kernel->yield('_start');^M + }else{^M + $kernel->delay( "alarm_reset", 10 );^M + }^M +}^M +^M sub begin_watchers {^M - my $heap = $_[HEAP];^M + my ($kernel, $heap) = @_[KERNEL, HEAP];^M ^M while ( my ( $service, $log_file ) = each %logs_to_watch ) {^M my $log_watcher = POE::Wheel::FollowTail->new^M @@ -81,6 +95,7 @@ $heap->{services}->{ $log_watcher->ID } = $service;^M $heap->{watchers}->{ $log_watcher->ID } = $log_watcher;^M }^M + $kernel->yield('alarm_reset');^M }^M ^M # Handle log resets the same way for each file. Simply recognize tha +t^M @@ -171,6 +186,8 @@ __DATA__^M # fullpath filter^M # ------------------------ ---------^M +/var/log/everything/current msg^M +/var/log/mail/current mail^M /var/log/cron cron^M /var/log/maillog mail^M /var/log/ppp.log ppp^M
Basically you need to receive an event when config file changes. You can setup an alarm to check this periodically, or any other means to be immediately notified.
Then, re-read your configuration file (you need to get rid of _DATA_ and use a procedure that returns you the hash), get the new files, delete your old FollowTail wheels, and create brand-new ones using begin_watchers.
I get advantage of the fact that you use %logs_to_watch like a "global", but I'd advise you to store all your "globals" to the HEAP.
Oh and a final note: the program doesn't change the log files, just shows you how to renew your wheels. And it isn't tested ;-)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Adding flexibility to Watching_Logs example in POE Cookbook
by shockers (Acolyte) on Nov 02, 2005 at 06:07 UTC | |
by Ultra (Hermit) on Nov 02, 2005 at 06:49 UTC |