|
NAMEFile::Tail::Dir - Tail all matching files in a given set of directories SYNOPSISTypical usage: use File::Tail::Dir;
my $tailer = File::Tail::Dir->new( filter => qr/.*access.*log$/,
processor => sub {
my ($filename, $lines) = @_;
...
},
);
$tailer->watch_files();
Or, subclass: package My::Tailer;
use Moose;
extends 'File::Tail::Dir';
# override standard 'process' method
sub process {
my ($self, $filename, $lines) = @_;
...
}
DESCRIPTIONMonitors and processes any lines appended to the end of one or more files in a given list of directories, keeping state between sessions, and using kernel notification of file change events to maximise efficiency. A list of directories is given to monitor, and filtering/exclude expressions allow just the files of interest to be selected for notification when lines are appended. This module was originally created to support lossless logging of many Apache web server log files to a Scribe-based logging subsystem (see File::Tail::Scribe, Log::Dispatch::Scribe), and hence key requirements are to keep state, to be able to resume from the last known state between interruptions (like server reboots), and to follow the renaming and creation of new files during log rotation. ALTERNATIVESLike File::Tail::Multi, File::Tail::App, File::Tail::FAM, File::Tail, File::Tail::Dir is yet another module to tail and process one or more files. What File::Tail::Dir provides that is different is:
CONSTRUCTORnew$tailer = File::Tail::Dir->new(%options); Options are as follows:
METHODSwatch_files$tailer->watch_files() Blocking call to watch for changes in files forever. When a change is detected, the process() method is called. processThis is the method invoked by watch_files() on file change, which in turn invokes the callback function specified by the 'processor' option. If no callback has been provided, it will print the filename and changed contents to standard output by default. This method may be overridden in a subclass instead of using the processor option. Its signature is: sub process {
my ($self, $filename, $lines) = @_;
...
}
The return value is ignored. running$running = $tailer->running(); # get status $tailer->running(0); # exit event loop This is set to true when the event loop in watch_files() is entered. It can be set to false (e.g. via a signal or in the process() method) to cause watch_files() to return after processing the current batch of events. Note that if running is set to false via signal, the event loop will not be exited until a new file change event is seen. save_state$tailer->save_state(); Saves internal state to file. This is always called when watch_files() completes normally, and is called periodically if autostate is enabled. However, you may wish to call it directly if you have installed a signal handler that might not allow watch_files() to complete. __PACKAGE__->install_signal_handlersFile::Tail::Dir->install_signal_handlers(); Installs default signal handlers. Once installed, on receiving any of HUP, INT, QUIT or TERM, all instances of File::Tail::Dir will attempt to save their state, and then exit. If used, this should be called before any File::Tail::Dir instance is created. AUTHORJon Schutz, "<jon at jschutz.net>" <http://notes.jschutz.net> BUGSPlease report any bugs or feature requests to "bug-file-tail-dir at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-Change-Dir>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. SUPPORTYou can find documentation for this module with the perldoc command. perldoc File::Tail::Dir You can also look for information at:
COPYRIGHT & LICENSECopyright 2012 Jon Schutz, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|