chiark / gitweb /
Reverse the contents of log files
authorMatthew Vernon <matthewv@chiark.greenend.org.uk>
Tue, 15 Apr 2014 15:53:15 +0000 (16:53 +0100)
committerMatthew Vernon <matthewv@chiark.greenend.org.uk>
Tue, 15 Apr 2014 16:51:28 +0000 (17:51 +0100)
Use "tac" to reverse files, meaning the logs are now output neatly in
reverse-chronological order.

The existing code tried to read everything in $webstump_home/.. ; we
now only try and open errs files; this involves changing the guard
condition to 0 from undef (since forwards * undef isn't undef).

webstump/scripts/html_output.pl

index 5503b4ae6104a3566e993c03f5ad1f69b87c9281..6ee32953025901a1442666f786444570acf4aa18 100644 (file)
@@ -640,22 +640,24 @@ sub scanlogs ($$$) {
     my $num= sub {
         local ($_) = @_;
         return $forwards * (
-            m/^errs$/ ? -1 :
-            m/^errs\.(\d+)(?:\.gz$)$/ ? $1 :
-            undef
+            m/^errs$/ ? 1 :
+            m/^errs\.(\d+)(?:\.gz$)$/ ? ($1+2) :
+            0
                            );
     };
     foreach my $leaf (
                       sort { $num->($a) <=> $num->($b) }
-                      grep { defined $num->($_) }
+                     grep { $num->($_) }
                       readdir LOGSDIR
                       ) {
         my $file= "$dir/$leaf";
-        if ($file =~ m/\.gz$/) {
-            open LOGFILE, "zcat $file |" or die "zcat $file $!";
+        if ($file =~ m/\/errs.*\.gz$/) {
+            open LOGFILE, "zcat $file | tac |" or die "zcat $file | tac $!";
+        } elsif ($file =~ /errs/) {
+            open LOGFILE, "tac $file |" or die "tac $file $!";
         } else {
-            open LOGFILE, "< $file" or die "$file $!";
-        }
+           die "Unexpected filename in scanlogs: $file";
+       }
         while (<LOGFILE>) {
             my $tgot= $callback->();
             next unless $tgot;