perldoc > POE::Wheel::FollowTail

📖 NAME

POE::Wheel::FollowTail — follow the tail of an ever-growing file

🚀 Quick Reference

Use CaseCommandDescription
📄 Watch a log file for new linesPOE::Wheel::FollowTail->new( Filename => "/var/log/system.log", InputEvent => "got_log_line" )Creates a wheel that emits InputEvent for each new line appended to the file
🔄 Handle log rotation / reset... ResetEvent => "got_log_rollover"Add ResetEvent to detect when the file is replaced or rolled over
⏱️ Adjust polling frequency... PollInterval => 10Check for new data every 10 seconds instead of the default 1
🎯 Seek to a specific position... Seek => $positionStart reading from an arbitrary byte offset (positive = from start, negative = from end)
💾 Save & restore file position$wheel->tell() then Seek => $saved_posPreserve position across program restarts
🔧 Custom data parsing... Filter => POE::Filter::Snort->new()Override the default newline filter with a custom parser
📌 Watch an already-open file handle... Handle => $fhFollow a file via its handle (cannot detect resets this way)
🛑 React to errors... ErrorEvent => "handle_error"Get notified when read operations fail

📝 SYNOPSIS

#!perl

use POE qw(Wheel::FollowTail);

POE::Session->create(
  inline_states => {
    _start => sub {
      $_[HEAP]{tailor} = POE::Wheel::FollowTail->new(
        Filename => "/var/log/system.log",
        InputEvent => "got_log_line",
        ResetEvent => "got_log_rollover",
      );
    },
    got_log_line => sub {
      print "Log: $_[ARG0]\n";
    },
    got_log_rollover => sub {
      print "Log rolled over.\n";
    },
  }
);

POE::Kernel->run();
exit;

📚 DESCRIPTION

POE::Wheel::FollowTail objects watch for new data at the end of a file and generate new events when things happen to the file. Its Filter parameter defines how to parse data from the file. Each new item is sent to the creator's session as an InputEvent event. Log rotation will trigger a ResetEvent.

POE::Wheel::FollowTail only reads from a file, so it doesn't implement a put() method.

🔧 PUBLIC METHODS

🆕 new

new() returns a new POE::Wheel::FollowTail object. As long as this object exists, it will generate events when the corresponding file's status changes.

new() accepts a small set of named parameters:

📡 event

event() allows a session to change the events emitted by a wheel without destroying and re-creating the object. It accepts one or more of the events listed in PUBLIC EVENTS. Undefined event names disable those events.

Stop handling log resets:

sub some_event_handler {
  $_[HEAP]{tailor}->event( ResetEvent => undef );
}

The events are described in more detail in PUBLIC EVENTS.

🆔 ID

The ID() method returns the wheel's unique ID. It's useful for storing the wheel in a hash. All POE::Wheel events should be accompanied by a wheel ID, which allows the wheel to be referenced in their event handlers.

sub setup_tailor {
  my $wheel = POE::Wheel::FollowTail->new(... incomplete ...);
  $_[HEAP]{tailors}{$wheel->ID} = $wheel;
}

See the example in ErrorEvent for a handler that will find this wheel again.

📏 tell

tell() returns the current position for the file being watched by POE::Wheel::FollowTail. It may be useful for saving the position program termination. new()'s Seek parameter may be used to resume watching the file where tell() left off.

sub handle_shutdown {
  # Not robust.  Do better in production.
  open my $save, ">", "position.save" or die $!;
  print $save $_[HEAP]{tailor}->tell(), "\n";
  close $save;
}

sub handle_startup {
  open my $save, "<", "position.save" or die $!;
  chomp(my $seek = <$save>);
  $_[HEAP]{tailor} = POE::Wheel::FollowTail->new(
    ...,
    Seek => $seek,
  );
}

📢 PUBLIC EVENTS

POE::Wheel::FollowTail emits a small number of events.

😴 IdleEvent

IdleEvent specifies the name of an event to be fired when POE::Wheel::FollowTail doesn't detect activity on the watched file.

$_[ARG0] contains the ID of the POE::Wheel::FollowTail object that fired the event.

📥 InputEvent

InputEvent sets the name of the event to emit when new data arrives into the tailed file. The event will be accompanied by two parameters:

See the SYNOPSIS for an example.

🔄 ResetEvent

ResetEvent names the event to be emitted whenever the wheel detects that the followed file has been reset. It's only available when watching files by name, as POE::Wheel::FollowTail must reopen the file after it has been reset.

ResetEvent comes with only one parameter, $_[ARG0], which contains the wheel's ID. See InputEvent for some notes about what may be done with wheel IDs.

See the SYNOPSIS for an example.

⚠️ ErrorEvent

ErrorEvent names the event emitted when POE::Wheel::FollowTail encounters a problem. Every ErrorEvent comes with four parameters that describe the error and its situation:

This error handler logs a message to STDERR and then shuts down the wheel. It assumes that the session is watching multiple files.

sub handle_tail_error {
  my ($operation, $errnum, $errstr, $wheel_id) = @_[ARG0..ARG3];
  warn "Wheel $wheel_id: $operation error $errnum: $errstr\n";
  delete $_[HEAP]{tailors}{$wheel_id};
}

📎 SEE ALSO

🐛 BUGS

👥 AUTHORS & COPYRIGHTS

Please see POE for more information about authors and contributors.

POE::Wheel::FollowTail
📖 NAME 🚀 Quick Reference 📝 SYNOPSIS 📚 DESCRIPTION 🔧 PUBLIC METHODS
🆕 new 📡 event 🆔 ID 📏 tell
📢 PUBLIC EVENTS
😴 IdleEvent 📥 InputEvent 🔄 ResetEvent ⚠️ ErrorEvent
📎 SEE ALSO 🐛 BUGS 👥 AUTHORS & COPYRIGHTS

Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-31 04:04 @216.73.217.152
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^