5 customization and extension of mytail-f.pl for megainstall log files.
7 with the ability to switch to the next file when one file is finished;
9 displaying filename and current package from time to time;
11 intelligent handling of incomplete lines
15 use File
::Basename
qw(basename);
18 use List
::Util
qw(maxstr);
19 use Time
::HiRes
qw(time sleep);
28 my $file = youngest
();
32 our @sleepscala = (2,3,5,8,13,21,34);
33 @sleepscala = (2,3,5) if $Opt{debug
};
34 my $sleepscalaindex = 0;
36 open GWFILE
, $file or die "Could not open '$file': $!";
43 open GWFILE
, $file or die "Could not open '$file': $!";
46 warn "lines[$lines]" if $Opt{debug
};
48 for ($curpos = tell(GWFILE
); $line = <GWFILE
>; $curpos = tell(GWFILE
)) {
50 # warn "i[$i]curpos[$curpos]" if $Opt{debug};
52 if ($line =~ /^\s+CPAN\.pm:/) {
53 ($currentpackage) = $line =~ /^\s+CPAN\.pm: Going to build\s+(\w[^\e]+\w)(?:\e.*)\s*$/;
55 if ($i > $lines - 10) {
57 my $localtime = sprintf "%02d:%02d:%02d", @time[2,1,0];
59 $fractime =~ s/\d+\.//;
61 my $prefix = sprintf "%5d %s.%s", $i, $localtime, substr($fractime,0,4);
63 my $filelabel = $file;
64 my $currentpackagelabel;
65 if ($currentpackage) {
66 $currentpackagelabel = $currentpackage;
67 $currentpackagelabel .= " "
68 while length $currentpackagelabel < length $filelabel;
70 while length $currentpackagelabel > length $filelabel;
72 if (length $lastline) {
73 print "\n(( $filelabel ))\n";
75 print "(( $filelabel ))\n";
77 if ($currentpackagelabel) {
78 print "(( $currentpackagelabel ))\n";
84 if (length $lastline) {
85 printf "\n%s %s%s", $prefix, $lastline, $line;
87 printf "%s %s", $prefix, $line;
100 } elsif ($i < $lines) {
103 sleep $sleepscala[$sleepscalaindex];
104 my $youngest = youngest
();
105 if ($sleepscalaindex<$#sleepscala) {
107 if ($sleepscalaindex==$#sleepscala) {
108 printf "\nINFO: max sleepscala reached at %s\n", scalar localtime;
111 printf "\rINFO: %s youngest[%s]", scalar localtime, basename
$youngest;
113 if ($youngest ne $file) {
114 print "\nswitching to $youngest\n";
119 seek(GWFILE
, $curpos, 0); # seek to where we had been
125 $dir ||= "/home/sand/andk-cpan-tools/logs/";
126 $pat ||= qr/^megainstall\..*\.out$/;
127 opendir my $dh, $dir or die "Could not opendir '$dir': $!";
128 my $youngest = maxstr
grep { $_ =~ $pat } readdir $dh;
129 File
::Spec
->catfile($dir,$youngest);