SYNOPSIS use Logfile::Tail::Switch; use Time::HiRes 'sleep'; # for subsecond sleep my $tail = Logfile::Tail::Switch->new( glob => "/s/example.com/syslog/http_access.*.log", ); # tail while (1) { my $line = $tail->getline; if (length $line) { print $line; } else { sleep 0.1; } } DESCRIPTION This class can be used to tail a file, but switch when a file of a newer name appears. For example, on an Spanel server, the webserver is configured to write to daily log files: /s//syslog/http_access.--
.log /s//syslog/https_access.--
.log So, when tailing you will need to switch to a new log file if you cross day boundary. When using this class, you specify a glob pattern of files, e.g. /s/example.com/syslog/http_access.*.log. Then you call the getline method. This class will first select the newest file (via asciibetical sorting) from the glob pattern and tail it. Then, periodically (by default at most every 5 seconds) the glob pattern will be checked again. If there is one or more newer files, they will be read in full and then tail-ed, until an even newer file comes along. For example, this is the list of files in /s/example.com/syslog at time t1: http_access.2017-06-05.log.gz http_access.2017-06-06.log http_access.2017-06-07.log http_access.2017-06-07.log will first be tail-ed. When http_access.2017-06-08.log appears at time t2, this file will be read from start to finish then tail'ed. When http_access.2017-06-09.log appears the next day, that file will be read then tail'ed. And so on. METHODS Logfile::Tail::Switch->new($glob [, \%opts ]) => obj Constructor. Known options: * check_freq => posint (default: 5) $tail->getline() => str Will return the next line or empty string if no new line is available. SEE ALSO File::Tail, File::Tail::Dir, IO::Tail Tie::Handle::TailSwitch tailswitch from App::tailswitch Spanel, http://spanel.info.