#!/usr/bin/perl # Simple log watcher. # Implements a single log file watcher using # POE::Wheel::FollowTail. May be extended to # watch multiple log files or relay alerts. # Copyright 2004 by Rocco Caputo. Free software. # Same terms as Perl itself. Have fun! use warnings; use strict; use POE qw(Wheel::FollowTail); POE::Session->create( inline_states => { _start => \&start_tailer, got_input => \&handle_input, got_error => \&handle_error, got_reset => \&handle_reset, }, ); POE::Kernel->run(); exit; sub start_tailer { my $heap = $_[HEAP]; $heap->{tailer} = POE::Wheel::FollowTail->new( Filename => "./test.log", InputEvent => "got_input", ErrorEvent => "got_error", ResetEvent => "got_reset", ); } sub handle_input { print "log: $_[ARG0]\n"; } sub handle_error { print "$_[ARG0] error $_[ARG1]: $_[ARG2]\n"; delete $_[HEAP]->{tailer}; } sub handle_reset { print "Log reset at ", scalar(localtime), "\n"; }